Changes between Version 65 and Version 66 of IrcFAQ


Ignore:
Timestamp:
04/15/2008 01:00:35 PM (7 years ago)
Author:
pbx
Comment:

reorganized into groups of questions

Legend:

Unmodified
Added
Removed
Modified
  • IrcFAQ

    v65 v66  
    3232Yes. http://wiki.python.org/moin/PythonBooks
    3333
    34 = Django questions =
     34= Installing and Deploying Django = #InstallAndDeploy
    3535
    3636== Which version should I use, the 0.96 release or the Subversion checkout? == #WhichVersion
     
    4242There will be several backwards-incompatible changes before the next release of Django (for example, the workings of the admin app will be changing), so it's officially recommended that production deployments stick to the 0.96 release until the next release is ready.
    4343
     44== When will the next release be out? -or- When will X branch be done? == #AreWeThereYet
     45
     46"When it's done" is the short answer. Fixed release dates are rarely set, but searching or browsing the developer list (http://groups.google.com/group/django-developers/) can be informative.
     47
     48If you always want to run with the bleeding-edge, just use the SVN trunk rather than the last release (it's kept stable and is updated nearly every day).
     49
     50
     51== I'm trying to install Django on Windows and something is weird. == #Windows
     52
     53Have you looked here? http://code.djangoproject.com/wiki/WindowsInstall
     54
     55
    4456== I'm using the development version (via Subversion) and when I ran "svn up" a bunch of stuff broke! == #SvnUp
    4557
     
    5062Also, when reading the documentation, keep a special eye out for the "New In Development Version" sections.
    5163
     64== What should I use for development -- the built-in server, mod_python, FastCGI? == #WhichServer
     65
     66It's generally easiest to use the [http://www.djangoproject.com/documentation/django-admin/#runserver-optional-port-number-or-ipaddr-port built-in development server] for development, since it automatically reloads your Python source files when it detects changes. Apache needs to be restarted to see changes to your source files (unless you set {{{MaxRequestsPerChild 1}}}, which you should do with caution since it is not suitable for production).
     67
     68Some prefer to replicate the production environment as closely as possible, meaning that if their deployed project uses mod_python then their development server does as well.
     69
     70== What database should I use? == #WhichDB
     71
     72For development, most people find SQLite to be fastest and simplest to run with -- just make sure the database file and its directory are writeable by the owner of the web server process. For production, PostgreSQL and MySQL are the most thoroughly-tested of the databases Django supports, but it's best to choose based on the needs of your applications; for example, applications which do very little writing of data to the DB will enjoy the speed of SQLite, but applications which involve many complex queries or which require robust concurrent-write features like transaction isolation will probably want to look at Postgres or MySQL (and, of course, MySQL is often handy simply because many shared hosting providers have it set up by default).
     73
     74
     75= Learning Django = #Learning
     76
    5277== Should I read the documentation on the djangoproject.com website, or djangobook.com? == #WhichDocs
    5378
    5479Start with the [http://www.djangoproject.com/documentation/ documentation] here, and then have a look at the book if you're interested; the documentation on djangoproject.com includes the official tutorial, and a number of comprehensive references which aren't currently available in the book.
    5580
     81== What's the difference between {{{null=True}}} and {{{blank=True}}} in models? == #NullVsBlank
     82
     83`null=True` means that the database will accept a `NULL` value for that field; `blank=True` means that Django's validation system won't complain about a missing value. If you use `blank=True` but ''not'' `null=True` you will need to have your code fill in a value before storage in the database -- specifying a default on a field, or putting something in the model's `save` method to generate a value are two good ways to handle this, and can be extremely useful when you want to calculate one field's value based on others.
     84
     85
     86= How to do Stuff = #HowTo
     87
    5688== How do I extend a model? I want to subclass django.contrib.auth.models.User. == #ModelSubclassing
    5789
    5890This feature has been added to the queryset-refactoring branch, but it is not available in either the trunk or a numbered release yet. Specific instructions for the User model can be found at http://www.b-list.org/weblog/2007/02/20/about-model-subclassing and http://www.djangobook.com/en/beta/chapter12/#cn226
    5991
     92== I think Ajax is awesome! How do I do Ajax with Django? == #Ajax
     93
     94Choose your favorite excellent Javascript library and go to it. Django provides serializers to JSON and XML, which you can read about in the documentation: http://www.djangoproject.com/documentation/serialization/
     95
     96Also see this helpful article from James Bennett (with bonus anti-Javascript-helpers rant!): http://www.b-list.org/weblog/2006/07/02/django-and-ajax
     97
     98== How do I customise the admin interface so all logged-in users can use it without screwing up anything? == #AllUsersAdmin
     99
     100The admin interface is designed for use by trusted site staff, not by any user -- if you don't trust a user with the level of access the admin application provides, you'll need to provide non-admin views for the actions you'd like to allow them to take.
     101
     102== How do I make extensive changes in the admin interface? == #ExtensiveChangesAdmin
     103
     104At the moment it's probably best not to; the admin app is fairly specialized and doesn't have a lot of places to customize behavior, so you'll usually end up writing less code by just rolling your own set of views. The newforms-admin branch, however, will significantly refactor the admin app to make customization much simpler.
     105
     106== I want to have some code run when the server/application starts. How do I do that? == #ServerStartup
     107
     108Both mod_python and FastCGI are structured in such a way that there's no such thing as "application startup" or "server startup"; the best solution is to place your "startup" code somewhere that's guaranteed to be imported early on in the request/response cycle (the `__init__.py` file of your project, or of a specific application you're using, can be a good place, because Python will execute code found there the first time it has to import the module; just be aware that referencing the same module in different ways, say by doing `from myproject.myapp import foo` in one place, and `from myapp import foo` in another, will cause that code to be executed once for each different way you import it).
     109
     110== Do I have to hard-code my media URL in all my templates for CSS, images and Javascript? == #MediaURL
     111
     112No; you can use {{ MEDIA_URL }}. If you're using the development version of django and generic views, you can use {{ MEDIA_URL }} without changing anything.
     113
     114If you're using the development version and render_to_response(), you'll have to include RequestContext, as described here: http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext
     115
     116If you're using 0.96, you can get the same functionality by creating a template context processor, as described: http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/
     117
     118
     119== How do I use Django in a shell script? == #Shell
     120
     121http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/
     122
     123== Can I use the Date/Time picker !JavaScript from the Admin in my own app? == #DatePicker
     124Short answer: No.
     125
     126Long answer: It is possible, but requires reusing the Admin JS and CSS, and is more trouble than it is worth. Most !JavaScript frameworks (such as [http://developer.yahoo.com/yui/ YUI], [http://dojotoolkit.org/ Dojo], [http://jquery.com/ jQuery], and [http://www.prototypejs.org/ Prototype]) provide similar functionality, either out of the box or through plugins. Additionally, there are many !JavaScript snippets available across the Web.
     127
     128== I want to repeat a bit of dynamic information (eg from a database) on many views. Do I have to change every view? ==
     129
     130No, you can use an [http://www.djangoproject.com/documentation/templates_python/#inclusion-tags inclusion tag].
     131
    60132== If I change my model, will {{{manage.py syncdb}}} update my database table? == #ModelChanges
    61133
    62134No, you'll need to manually change your database table. If you use `manage.py sqlall` on your app to produce a SQL file before editing your models, you can run it again afterwards and use the difference between the two to see what you need to change in the database.
    63135
    64 == What should I use for development -- the built-in server, mod_python, FastCGI? == #WhichServer
    65 
    66 It's generally easiest to use the built-in development server, since it automatically reloads your Python source files when it detects changes. (Some prefer to replicate the production environment as closely as possible, meaning that if their deployed project uses mod_python then their development server does as well.)
    67 
    68 == What's the difference between {{{null=True}}} and {{{blank=True}}} in models? == #NullVsBlank
    69 
    70 `null=True` means that the database will accept a `NULL` value for that field; `blank=True` means that Django's validation system won't complain about a missing value. If you use `blank=True` but ''not'' `null=True` you will need to have your code fill in a value before storage in the database -- specifying a default on a field, or putting something in the model's `save` method to generate a value are two good ways to handle this, and can be extremely useful when you want to calculate one field's value based on others.
    71 
    72 == I think Ajax is awesome! How do I do Ajax with Django? == #Ajax
    73 
    74 Choose your favorite excellent Javascript library and go to it. Django provides serializers to JSON and XML, which you can read about in the documentation: http://www.djangoproject.com/documentation/serialization/
    75 
    76 Also see this helpful article from James Bennett (with bonus anti-Javascript-helpers rant!): http://www.b-list.org/weblog/2006/07/02/django-and-ajax
    77 
    78 == Is there a free CMS available for Django? == #CMS
    79 
    80 At this point there is nothing well-established (like Plone, for instance). In practice, people mean so many different things by "CMS" that it may be hard to get a straight answer. This question is often asked by newcomers; one recommendation is to learn a bit of Django and see just how easy it is to make a site that does what you want. If you're in a big rush, there's always Ellington:  http://www.ellingtoncms.com/
    81 
    82 == What database should I use? == #WhichDB
    83 
    84 For development, most people find SQLite to be fastest and simplest to run with -- just make sure the database file and its directory are writeable by the owner of the web server process. For production, PostgreSQL and MySQL are the most thoroughly-tested of the databases Django supports, but it's best to choose based on the needs of your applications; for example, applications which do very little writing of data to the DB will enjoy the speed of SQLite, but applications which involve many complex queries or which require robust concurrent-write features like transaction isolation will probably want to look at Postgres or MySQL (and, of course, MySQL is often handy simply because many shared hosting providers have it set up by default).
     136
     137
     138= Troubleshooting =
    85139
    86140== The admin is working, but it can't find the Javascript and CSS and image files. == #AdminFiles
     
    90144If you're running Apache, read this: http://www.djangoproject.com/documentation/modpython/#serving-media-files
    91145
    92 == Do I really have to restart Apache every time I change my code in order to see my changes? == #UseTheDevServer
    93 
    94 In short, yes. Apache is great for deployment, but generally not the best choice for development -- use the [http://www.djangoproject.com/documentation/django-admin/#runserver-optional-port-number-or-ipaddr-port built in development server instead]. It automatically reloads when it detects code changes.
    95 
    96 == Do I have to hard-code my media URL in all my templates for CSS, images and Javascript? == #MediaURL
    97 
    98 No; you can use {{ MEDIA_URL }}. If you're using the development version of django and generic views, you can use {{ MEDIA_URL }} without changing anything.
    99 
    100 If you're using the development version and render_to_response(), you'll have to include RequestContext, as described here: http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext
    101 
    102 If you're using 0.96, you can get the same functionality by creating a template context processor, as described: http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/
    103 
    104 == I'm trying to install Django on Windows and something is weird. == #Windows
    105 
    106 Have you looked here? http://code.djangoproject.com/wiki/WindowsInstall
    107 
    108 == What editor is best for Django? == #WhichEditor
    109 
    110 [wiki:UsingVimWithDjango Vim]. No, wait, [wiki:Emacs Emacs]. A lot of people seem to like TextMate, too.
    111 
    112 The best editor is the editor ''you'' prefer.
    113 
    114 == How do I customise the admin interface so all logged-in users can use it without screwing up anything? == #AllUsersAdmin
    115 
    116 The admin interface is designed for use by trusted site staff, not by any user -- if you don't trust a user with the level of access the admin application provides, you'll need to provide non-admin views for the actions you'd like to allow them to take.
    117 
    118 == How do I make extensive changes in the admin interface? == #ExtensiveChangesAdmin
    119 
    120 At the moment it's probably best not to; the admin app is fairly specialized and doesn't have a lot of places to customize behavior, so you'll usually end up writing less code by just rolling your own set of views. The newforms-admin branch, however, will significantly refactor the admin app to make customization much simpler.
    121 
    122 == I have created several users, but only the superuser is able to log into the admin == #OrdinaryUserCantLoginAdmin
    123 
    124 In .95 and prior releases, you cannot put a plain password when creating a new user in admin -- the form expects a hashed password in the format which will be stored in the database. In Django 0.96 and later, this is not a problem.
    125 
    126 Also, keep in mind that admin access requires the "is_active" and "is_staff" boxes to be checked for the user.
    127 
    128 == When will the next release be out? -or- When will X branch be done? == #AreWeThereYet
    129 
    130 "When it's done" is the short answer. Fixed release dates are rarely set, but searching or browsing the developer list (http://groups.google.com/group/django-developers/) can be informative.
    131 
    132 If you always want to run with the bleeding-edge, just use the SVN trunk rather than the last release (it's kept stable and is updated nearly every day).
    133 
    134 == I want to repeat a bit of dynamic information (eg from a database) on many views. Do I have to change every view? ==
    135 
    136 No, you can use an [http://www.djangoproject.com/documentation/templates_python/#inclusion-tags inclusion tag].
     146
    137147
    138148== Why isn't my template tag or filter working? == #TemplateTagsAndFilters
     
    149159  * restart the webserver (yes, even if you're using runserver)
    150160
    151 == I want to have some code run when the server/application starts. How do I do that? ==
    152 
    153 Both mod_python and FastCGI are structured in such a way that there's no such thing as "application startup" or "server startup"; the best solution is to place your "startup" code somewhere that's guaranteed to be imported early on in the request/response cycle (the `__init__.py` file of your project, or of a specific application you're using, can be a good place, because Python will execute code found there the first time it has to import the module; just be aware that referencing the same module in different ways, say by doing `from myproject.myapp import foo` in one place, and `from myapp import foo` in another, will cause that code to be executed once for each different way you import it).
    154161
    155162== I have a `DateField` or `DateTimeField` with a default value of `now()`, but it's not working! ==
     
    175182More information on exactly what changed regarding Unicode in Django is available on the UnicodeBranch page.
    176183
    177 == How do I use Django in a shell script? == #Shell
    178 
    179 http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/
    180 
    181 == Can I use the Date/Time picker !JavaScript from the Admin in my own app? == #DatePicker
    182 Short answer: No.
    183 
    184 Long answer: It is possible, but requires reusing the Admin JS and CSS, and is more trouble than it is worth. Most !JavaScript frameworks (such as [http://developer.yahoo.com/yui/ YUI], [http://dojotoolkit.org/ Dojo], [http://jquery.com/ jQuery], and [http://www.prototypejs.org/ Prototype]) provide similar functionality, either out of the box or through plugins. Additionally, there are many !JavaScript snippets available across the Web.
    185 
    186 == The ticket tracker thinks I'm a spammer! == #TracTrouble
    187 
    188 You need to register: http://www.djangoproject.com/accounts/register/
    189 
    190 == Is there a channel bot? == #DjangoBot
    191 
    192 Yes, it's very handy -- see DjangoBot for more.
    193 
    194 == python manage.py gives cannot find bdb.settings, but I can import bdb from the python prompt ==
    195 
    196 You have named your project 'bdb' which is the name of an existing python module. Do not name your project after and existing python module
     184
     185
     186= Resources, Tools, and Code = #Resources
     187
     188== What editor is best for Django? == #WhichEditor
     189
     190[wiki:UsingVimWithDjango Vim]. No, wait, [wiki:Emacs Emacs]. A lot of people seem to like TextMate, too. The best editor is the editor ''you'' prefer.
     191
     192== Is there a free CMS available for Django? == #CMS
     193
     194At this point there is nothing well-established (like Plone, for instance). In practice, people mean so many different things by "CMS" that it may be hard to get a straight answer. This question is often asked by newcomers; one recommendation is to learn a bit of Django and see just how easy it is to make a site that does what you want. If you're in a big rush, there's always Ellington:  http://www.ellingtoncms.com/
    197195
    198196== Where can I find example code? == #ShowMeTheCode
     
    205203 * http://github.com/search?q=django
    206204
     205
     206= IRC and djangoproject.com Miscellany = #Misc
     207
     208== The ticket tracker thinks I'm a spammer! == #TracTrouble
     209
     210You need to register: http://www.djangoproject.com/accounts/register/
     211
     212
     213== Is there a channel bot? == #DjangoBot
     214
     215Yes, it's very handy -- see DjangoBot for more.
     216
Back to Top