django

Django restart server or httpd

In django framework,When there are changes in urls.py or model.py or views.py .We would restart httpd. But as the documentation says we could restart runserver to get the latest changes. Which is the best efficient way for doing the above ...

TypeError in Django with python 2.7

Hey, new to Django and needing assistance, when I add my model to the admin interface in Django it appeares fine, but when I try to add or delete an entry in the database I get: TypeError at /admin/Users/user/add/ coercing to Unicode: need string or buffer, tuple found I done a google search and added: def __str__(self): re...

Python, how to instantiate classes from a class stored in a database?

I'm using Django and want to be able to store classes in a database for things like forms and models so that I can easily make them creatable through a user interface since they are just stored in the database as opposed to a regular file. I don't really know a whole lot about this and am not sure if this is a situation where I need to u...

WSGI based Python web frameworks

I keep hitting road blocks with Django and have read about Pylons. Pylons seemed to be exactly what I needed (greener grass), but then I realized that they have global variables all over the place and loads of black magic infused by dark spirits (spirits so dark that they even kill unicorns). Is there anything out there that is enterpri...

.Stay on SSL across redirects

Parts of my site should be server over SSL. I'm only using paths (not full URLs) in links so users stay on SSL when opening links. However, when I use the redirect shortcut function the user is redirected to a non-SSL URL. Is there any way to specify that the redirect should happen over SSL? It would be best if redirects behaved just li...

How do I resuse HTML snippets in a django view

I am working on a django project (my first), and in one of my views, I have a sophisticated html snippet with JS weaved within it. I would like to reuse this "component" somewhere else in the same view. Is there a way of achieving this? Please let me know if this design is faulty to begin with? ...

Rewriting "SELECT DISTINCT ON ..." using Django's ORM

I am using the following model with Django: class Hit(Model): image = ForeignKey(Image) user = ForeignKey(User) timestamp = DateTimeField(auto_now_add = True) What I need is basically a list that contains the count of "first hits" (i.e. hits with no earlier timestamp for the same image) for every user to create sort of a r...

Is there a way to make a select faster by making it read only in django's ORM?

If I am just getting a list of users, and I have no intention of updating this list, do I have the option of marking the query as 'read only' somehow? Reason being, I know most ORM's keep some sort of change tracking on the rows returned. So if I know before hand that I don't need to update anything, was curious if I could tell the ORM...

Django default_from_email name

I am looking to add a name to my default_from_email address in Django and wanted to know whether you do this through the settings.py file? you have your different options. DEFAULT_FROM_EMAIL EMAIL_HOST EMAIL_PASSWORD ... but the email result still ends in from: [email protected] and I would like to change this into My Domain inste...

Django: Problem reading multi valued POST variable

I'm missing something obvious here. I am trying to process a POST request that contains a mixture of single value and multi value variables. I can get the single valued variables using request.POST.get('variable_name'), for example: logging.debug('sale_date: ' + request.POST.get('SALEDATE')) However, I can't get the multi value variab...

Django and Common Access Cards (CAC)

A web app written in Python is planned, Django is a leading contender as framework. One requirement is CAC access, wihout the need to hand enter username and password. From what I can tell, CAC access is not part of the "batteries" included with Django. As a monolithic framework (not necessarily a bad attribute) Django has a rep for b...

Creating a Relation in __init__ of a model (in Django)

Lets assume I had the following Model class A(Models.model): def __init__(self,data): B(a=self,data=data).save() class B(Models.model): data = somefieldtype a = Models.models.ForeignKey('A') now as you might suspect, there is an error in this Model definintion, as one cannot create a relation to the A instance before a...

Python / Django Web service Confusion

I am trying to explore more about web service in Python/Django and to be honest i am quite confused. There are so many things like SOAPpy, XML-RPC, JSON-RPC RESTful, web service. Basically all i want to know is what is the standard way of implementing web service in Python/Django and has anyone implemented in live production environmen...

FormPreview with djangoforms.ModelForm

I'm confused about which to use djangoforms.ModelForm or django.forms.Form took djangoforms.ModelForm trying form post, preview and edit with same template. post and edit work. Can you point me to an example with combined FormPreview, GAE SDK and djangoforms.ModelForm usage? I try to avoid patch the latest django and think the SDK comes ...

Filtering Model formsets

First try at playing with model formsets with django and was wondering how to filter by the logged in user. The view below renders a form with all the profiles when I only want them to list one (the user's one). def create_profile(request): ProfileFormSet = modelformset_factory(Profile) if request.method == 'POST': formset...

Problem when Serving static files in Django

I have my css file in /var/www/media/static/style.css and added (r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': '/var/www/media/static'}), to my urls but when I go to http://localhost:8000/media/style.css I get: "Page not found: /media/style.css" what is wrong? ...

Running django site in multiserver environment - how to handle sessions?

My django-powered site sits behind a Apache-based loadbalancer. There also is a server handling static file requests, but that's simple. What bothers me is how to handle a user who can be thrown to any of the application servers by the load-balancer? They all share the same DB-cluster (is it smart? Or should I separate it here too?), s...

Django GenericManyToMany ?

Hi all! I want to make my Book model belongs to multiple Libraries, Collections, References and Editors, together. Is it possible to do it with generic relations ? Like that : content_type = generic.GenericManyToMany(ContentType) Thanks. from django.conf import settings from django.contrib.contenttypes import generic from django.con...

How to work with settings in Django

I want to keep some global settings for my project in Django. I need to have access to these settings from the code. For example, I need to set a current theme for my site that I can set using admin console or from the code. Or I need to set a tagline that will show in the header of all pages. I suppose I should use models for keeping th...

Flask for Python - architectural question regarding the system.

I've been using Django and Django passes in a request object to a view when it's run. It looks like (from first glance) in Flask the application owns the request and it's imported (as if it was a static resource). I don't understand this and I'm just trying to wrap my brain around WSGI and Flask, etc. Any help is appreciated. ...