Questions tagged [django]

Django is an open-source server-side web application framework written in Python. It is designed to reduce the effort required to create complex data-driven websites and web applications, with a special focus on less code, no-redundancy and being more explicit than implicit.

PyPI

Django: The Web framework for perfectionists with deadlines

Django is a high-level web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers and maintained by the non-profit Django Software Foundation (DSF). it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

Django follows the (model-view-controller) architectural pattern. This consists of:

  • an object-relational mapper that mediates between data models
    (Python classes) and a relational database ("Model")

  • a system for processing requests with a web templating system ("View")

  • a regular-expression-based URL dispatcher ("Controller")

The team prefers to think of Django as an "MTV" framework, where 'M' is the model, 'T' is the template and 'V' is view.

In , 'views' describe which data are presented while 'templates' describe how that data is presented.

Resources

Useful books

Tutorials

Newsletters

Podcasts

Popular Third Party Apps

Websites Using Django

See also:

309060 questions
53
votes
5 answers

Django set range for integer model field as constraint

I have a django model, class MyModel(models.Model) qty = model.IntegerField() where I want to set constraint for qty something like this, >0 or <0,i.e the qty can be negative or positive but can not be 0. Is there any straight forward way to…
Md. Tanvir Raihan
  • 4,075
  • 9
  • 37
  • 70
53
votes
5 answers

Count number of records by date in Django

I have a model similar to the following: class Review(models.Model): venue = models.ForeignKey(Venue, db_index=True) review = models.TextField() datetime_created = models.DateTimeField(default=datetime.now) I'd like to query the…
doza
  • 893
  • 1
  • 7
  • 12
53
votes
3 answers

How do I call a Django function on button click?

I am trying to write a Django application and I am stuck at how I can call a view function when a button is clicked. In my template, I have a link button as below, when clicked it takes you to a different webpage:
Dev
  • 1,529
  • 4
  • 24
  • 36
53
votes
3 answers

Bad Django / uwsgi performance

I am running a django app with nginx & uwsgi. Here's how i run uwsgi: sudo uwsgi -b 25000 --chdir=/www/python/apps/pyapp --module=wsgi:application --env DJANGO_SETTINGS_MODULE=settings --socket=/tmp/pyapp.socket --cheaper=8 --processes=16 …
Maverick
  • 1,458
  • 2
  • 21
  • 35
53
votes
1 answer

How to query directly the table created by Django for a ManyToMany relation?

I have a model MyModel2 with a ManyToManyField related to another model MyModel1. How can I get the pairs mymodel1.id, mymodel2.id, as represented in the table Django creates for this relation? Do I have to do a raw SQL query on this table or is it…
jul
  • 36,404
  • 64
  • 191
  • 318
53
votes
3 answers

Django Forms: pass parameter to form

How do I pass a parameter to my form? someView().. form = StylesForm(data_dict) # I also want to pass in site_id here. class StylesForm(forms.Form): # I want access to site_id here
user984003
  • 28,050
  • 64
  • 189
  • 285
53
votes
7 answers

How do I pass template context information when using HttpResponseRedirect in Django?

I have a form that redirects to the same page after a user enters information (so that they can continue entering information). If the form submission is successful, I'm returning HttpResponseRedirect(request.path) which works fine. However, I'd…
Jeff
  • 14,831
  • 15
  • 49
  • 59
53
votes
15 answers

Disable button after submit with jQuery

I know there are a lot of questions about it, but I tried several solutions, and nothing works. In my django app I have a form:
I wan't to disable the button once the user has…
Juliette Dupuis
  • 1,027
  • 2
  • 13
  • 22
53
votes
5 answers

How do I get the default value for a field in a Django model?

I have a Django model with some fields that have default values specified. I am looking to grab the default value for one of these fields for us later on in my code. Is there an easy way to grab a particular field's default value from a model?
mikec
  • 3,543
  • 7
  • 30
  • 34
53
votes
2 answers

OneToOneField and Deleting

I have the following model: from django.db import models from django.contrib.auth.models import User class Profile(models.Model): user = models.OneToOneField(User) # ... def __unicode__(self): return u'%s %s' %…
Nick
  • 8,049
  • 18
  • 63
  • 107
53
votes
2 answers

What does this "-" in jinja2 template engine do?

I am learning jinja2 because Google App Engine recommends it. I found this example on Wikipedia: http://en.wikipedia.org/wiki/Jinja_%28template_engine%29 {%- for item in item_list %} {{ item }}{% if not loop.last %},{% endif %} {%- endfor…
Gaby Solis
  • 2,427
  • 5
  • 21
  • 27
52
votes
3 answers

Generic many-to-many relationships

I'm trying to create a messaging system where a message's sender and recipients can be generic entities. This seems fine for the sender, where there is only object to reference (GenericForeignKey) but I can't figure out how to go about this for the…
Noel Evans
  • 8,113
  • 8
  • 48
  • 58
52
votes
6 answers

Django form with BooleanField always invalid unless checked

I have an application that uses the following form: class ConfirmForm(forms.Form): account_name = forms.CharField(widget=forms.HiddenInput) up_to_date = forms.BooleanField(initial=True) I use the form in the following template exerpt:
dhowland
  • 643
  • 1
  • 5
  • 12
52
votes
7 answers

Using Sql Server with Django in production

Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it. I'm…
Josh Smeaton
  • 47,939
  • 24
  • 129
  • 164
52
votes
5 answers

Django templates - split string to array

I have a model field, which stores a list of URLs (yeah, I know, that's wrong way) as url1\nurl2\nurl3<...>. I need to split the field into an array in my template, so I created the custom filter: @register.filter(name='split') def split(value,…
artem
  • 16,382
  • 34
  • 113
  • 189
1 2 3
99
100