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
54
votes
2 answers

Is APITest with Query params different then just normal url?

I'm writing some unit tests against an API that either returns all the books, or only returns the books of the given genre in the query params. This seems to be working when I hit it in my local dev server. However, it doesn't even go into the else…
user133688
  • 6,864
  • 3
  • 20
  • 36
54
votes
3 answers

Simple approach to launching background task in Django

I have a Django website, and one page has a button (or link) that when clicked will launch a somewhat long running task. Obviously I want to launch this task as a background task and immediately return a result to the user. I want to implement this…
Marc
  • 3,386
  • 8
  • 44
  • 68
54
votes
4 answers

How do I get all the variables defined in a Django template?

I'm new to Django and I wonder if there is a way to dump all the variables available to a template for debugging purposes. In Python I might use something like locals(), is there something equivalent for the default template engine? Note: suppose I…
Blaine Osepchuk
  • 1,067
  • 1
  • 9
  • 17
54
votes
4 answers

What is the canonical way to find out if a Django model is saved to db?

I generally check if obj.pk to knwo if the objects is saved. This wont work however, if you have primary_key = True set on some fields. Eg I set user = models.OneToOneField(User, primary_key=True) on my UserProfile. What is the canonical way to find…
agiliq
  • 7,518
  • 14
  • 54
  • 74
54
votes
8 answers

Django: SocialApp matching query does not exist

I'm using django-allauth, and I configured localhost:9000/admin/ with the following details: socialapp . provider: Name: Client id: App ID, or consumer key Key: Secret: etc . I set SITE_ID = 2 (because I changed the default site example.com to…
masterofdestiny
  • 2,751
  • 11
  • 28
  • 40
54
votes
6 answers

Django admin and showing thumbnail images

I'm trying to show thumbnail images in Django admin, but I can only see the path to the images, but not the rendered images. I don't know what I'm doing wrong. Server media URL: from django.conf import settings (r'^public/(?P.*)$',…
Asinox
  • 6,747
  • 14
  • 61
  • 89
54
votes
5 answers

Django: Can I create a QueryDict from a dictionary?

Imagine that I have a dictionary in my Django application: dict = {'a': 'one', 'b': 'two', } Now I want to easily create an urlencoded list of GET parameters from this dictionary. Of course I could loop through the dictionary, urlencode keys and…
winsmith
  • 20,791
  • 9
  • 39
  • 49
54
votes
4 answers

How to get an array in Django posted via Ajax

When I try to send an array to Django via Ajax (jQuery) JavaScript code: new_data = ['a','b','c','d','e']; $.get('/pythonPage/', {'data': new_data},function(data){}); and I try to read the array: Python: request.GET.get("data[]") I get only the…
Erez
  • 2,615
  • 2
  • 21
  • 27
54
votes
8 answers

Actions triggered by field change in Django

How do I have actions occur when a field gets changed in one of my models? In this particular case, I have this model: class Game(models.Model): STATE_CHOICES = ( ('S', 'Setup'), ('A', 'Active'), ('P', 'Paused'), …
Jeff Bradberry
  • 1,597
  • 1
  • 12
  • 11
54
votes
2 answers

django: how do I query based on GenericForeignKey's fields?

I'm new in using GenericForeignKey, and I couldn't make it to work in a query statement. The tables are roughly like the following: class Ticket(models.Model): issue_ct = models.ForeignKey(ContentType, related_name='issue_content_type') …
Shang Wang
  • 24,909
  • 20
  • 73
  • 94
54
votes
1 answer

django OneToOne reverse access

I have these simple classes Class A(models.Model): ... Class Meta(models.Model): a = models.OnetoOneField(A, primary_key=True) width = models.IntegerField(default=100) but when I do a = A() meta = Meta() a.save() meta.a =…
WindowsMaker
  • 3,132
  • 7
  • 29
  • 46
54
votes
1 answer

django: Purpose of django.utils.functional.SimpleLazyObject?

I ran into an issue where I assigned request.user to a variable called prior_user, then essentially authenticated the user, then checked to see if request.user != prior_user. I expected them not to be the same and that prior_user should contain…
donogood
  • 555
  • 1
  • 4
  • 7
54
votes
3 answers

Django: Hide button in template, if user is not super-user

How do you get your template/view to recognize whether or not a logged in user is a super user or not? There are certain buttons on my forms (in the template) that I want completely hidden if the user is not a super-user How would you go about…
53
votes
12 answers

How to render menu with one active item with DRY?

I would like to render a constructions like: Home Community About Where Community is selected menu item. I have menu with same options for several templates but I would not like…
sergzach
  • 6,578
  • 7
  • 46
  • 84
53
votes
4 answers

Is the Lift framework as "easy" as Ruby on Rails or Django?

Just wondering if anyone has experience with the three. I have used read through some RoR and used Django. They seem fairly easy to use. Is lift "easy" like these two are? I know easy is subjective and has no context here. I mean in a very high…
johnny
  • 19,272
  • 52
  • 157
  • 259