Changeset 1904
- Timestamp:
- 01/10/06 23:07:38 (3 years ago)
- Files:
-
- django/branches/magic-removal/AUTHORS (modified) (1 diff)
- django/branches/magic-removal/django/contrib/admin/media/css/global.css (modified) (1 diff)
- django/branches/magic-removal/django/contrib/admin/templates/widget/one_to_one.html (copied) (copied from django/trunk/django/contrib/admin/templates/widget/one_to_one.html)
- django/branches/magic-removal/django/core/formfields.py (modified) (1 diff)
- django/branches/magic-removal/django/core/management.py (modified) (3 diffs)
- django/branches/magic-removal/django/core/template/defaultfilters.py (modified) (1 diff)
- django/branches/magic-removal/docs/authentication.txt (modified) (2 diffs)
- django/branches/magic-removal/docs/cache.txt (modified) (1 diff)
- django/branches/magic-removal/docs/db-api.txt (modified) (1 diff)
- django/branches/magic-removal/docs/django-admin.txt (modified) (4 diffs)
- django/branches/magic-removal/docs/email.txt (modified) (1 diff)
- django/branches/magic-removal/docs/generic_views.txt (modified) (2 diffs)
- django/branches/magic-removal/docs/request_response.txt (modified) (2 diffs)
- django/branches/magic-removal/docs/sessions.txt (modified) (4 diffs)
- django/branches/magic-removal/docs/settings.txt (modified) (3 diffs)
- django/branches/magic-removal/docs/templates_python.txt (modified) (3 diffs)
- django/branches/magic-removal/docs/templates.txt (modified) (2 diffs)
- django/branches/magic-removal/docs/tutorial01.txt (modified) (13 diffs)
- django/branches/magic-removal/docs/tutorial02.txt (modified) (9 diffs)
- django/branches/magic-removal/docs/tutorial03.txt (modified) (13 diffs)
- django/branches/magic-removal/docs/tutorial04.txt (modified) (3 diffs)
- django/branches/magic-removal/docs/url_dispatch.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/AUTHORS
r1879 r1904 83 83 Luke Plant <http://lukeplant.me.uk/> 84 84 plisk 85 Daniel Poelzleithner <http://poelzi.org/> 85 86 Brian Ray <http://brianray.chipy.org/> 86 87 Oliver Rutherfurd <http://rutherfurd.net/> django/branches/magic-removal/django/contrib/admin/media/css/global.css
r1839 r1904 123 123 124 124 /* FORM BUTTONS */ 125 input[type=submit], input[type=button], .submit-row input { border:1px solid #ccc; background:white url(../img/admin/nav-bg.gif) bottom repeat-x; }125 input[type=submit], input[type=button], .submit-row input { border:1px solid #ccc; background:white url(../img/admin/nav-bg.gif) bottom repeat-x; color:black; } 126 126 input[type=submit]:active, input[type=button]:active { background-image:url(../img/admin/nav-bg-reverse.gif); background-position:top; } 127 127 input[type=submit].default, .submit-row input.default { border:2px solid #5b80b2; padding:3px; background:white url(../img/admin/default-bg.gif) bottom repeat-x; font-weight:bold; color:white; } django/branches/magic-removal/django/core/formfields.py
r1873 r1904 812 812 t = t.replace(microsecond=int(part_list[1])) 813 813 return t 814 except (ValueError, TypeError ):814 except (ValueError, TypeError, AttributeError): 815 815 return None 816 816 html2python = staticmethod(html2python) django/branches/magic-removal/django/core/management.py
r1888 r1904 946 946 createcachetable.args = "[tablename]" 947 947 948 def run_shell(): 949 "Runs a Python interactive interpreter" 950 import code 951 code.interact() 952 run_shell.args = '' 953 948 954 # Utilities for command-line script 949 955 … … 959 965 'installperms': installperms, 960 966 'runserver': runserver, 967 'shell': run_shell, 961 968 'sql': get_sql_create, 962 969 'sqlall': get_sql_all, … … 1039 1046 else: 1040 1047 action_mapping[action](username, email, password) 1041 elif action in ('init', 'init-minimal', ' validate'):1048 elif action in ('init', 'init-minimal', 'shell', 'validate'): 1042 1049 action_mapping[action]() 1043 1050 elif action == 'inspectdb': django/branches/magic-removal/django/core/template/defaultfilters.py
r1818 r1904 137 137 """ 138 138 from django.utils.text import wrap 139 return wrap( value, int(arg))139 return wrap(str(value), int(arg)) 140 140 141 141 def ljust(value, arg): django/branches/magic-removal/docs/authentication.txt
r1775 r1904 171 171 --------- 172 172 173 **This only applies to the Django development version.** Previous versions, 174 s uch as Django 0.90, used simple MD5 hashes without password salts.173 Previous versions, such as Django 0.90, used simple MD5 hashes without password 174 salts. 175 175 176 176 The ``password`` field of a ``User`` object is a string in this format:: … … 315 315 is not anonymous. 316 316 317 **New in the Django development version**: ``user_passes_test()`` takes an 318 optional ``login_url`` argument, which lets you specify the URL for your login 319 page (``/accounts/login/`` by default). 317 ``user_passes_test()`` takes an optional ``login_url`` argument, which lets you 318 specify the URL for your login page (``/accounts/login/`` by default). 320 319 321 320 Example in Python 2.3 syntax:: django/branches/magic-removal/docs/cache.txt
r1818 r1904 49 49 this is multi-process- and thread-safe. 50 50 51 dummy:/// **New in Django development version.** 52 Doesn't actually cache; just implements the 51 dummy:/// Doesn't actually cache; just implements the 53 52 cache backend interface and doesn't do 54 53 anything. This is an easy way to turn off django/branches/magic-removal/docs/db-api.txt
r1884 r1904 223 223 ---------- 224 224 225 **New in Django development version.**226 227 225 By default, keyword argument queries are "AND"ed together. If you have more complex query 228 226 requirements (for example, you need to include an ``OR`` statement in your query), you need django/branches/magic-removal/docs/django-admin.txt
r1518 r1904 7 7 8 8 The ``django-admin.py`` script should be on your system path if you installed 9 Django via its setup.pyutility. If it's not on your path, you can find it in9 Django via its ``setup.py`` utility. If it's not on your path, you can find it in 10 10 ``site-packages/django/bin`` within your Python installation. Consider 11 11 symlinking to it from some place on your path, such as ``/usr/local/bin``. 12 12 13 In addition, ``manage.py`` is automatically created in each Django project. 14 ``manage.py`` is a thin wrapper around ``django-admin.py`` that takes care of 15 two things for you before delegating to ``django-admin.py``: 16 17 * It puts your project's package on ``sys.path``. 18 19 * It sets the ``DJANGO_SETTINGS_MODULE`` environment variable so that it 20 points to your project's ``settings.py`` file. 21 22 Generally, when working on a single Django project, it's easier to use 23 ``manage.py``. Use ``django-admin.py`` with ``DJANGO_SETTINGS_MODULE``, or the 24 ``--settings`` command line option, if you need to switch between multiple 25 Django settings files. 26 13 27 Usage 14 28 ===== 15 29 16 30 ``django-admin.py action [options]`` 31 ``manage.py action [options]`` 17 32 18 33 ``action`` should be one of the actions listed in this document. ``options``, … … 55 70 address and password. 56 71 57 **New in Django development version:** You can specify 58 ``username email password`` on the command line, for convenient use in shell 59 scripts. Example:: 72 You can specify ``username email password`` on the command line, for convenient 73 use in shell scripts. Example:: 60 74 61 75 django-admin.py createsuperuser john john@example.com mypassword … … 212 226 ``django-admin.py`` will use the DJANGO_SETTINGS_MODULE environment variable. 213 227 228 Note that this option is unnecessary in ``manage.py``, because it takes care of 229 setting ``DJANGO_SETTINGS_MODULE`` for you. 230 214 231 --pythonpath 215 232 ------------ … … 223 240 variable. 224 241 242 Note that this option is unnecessary in ``manage.py``, because it takes care of 243 setting the Python path for you. 244 225 245 .. _import search path: http://diveintopython.org/getting_to_know_python/everything_is_an_object.html 226 246 django/branches/magic-removal/docs/email.txt
r1810 r1904 119 119 =========================== 120 120 121 **New in Django development version.**122 123 121 `Header injection`_ is a security exploit in which an attacker inserts extra 124 122 e-mail headers to control the "To:" and "From:" in e-mail messages that your django/branches/magic-removal/docs/generic_views.txt
r1775 r1904 130 130 template's context. 131 131 132 ``processors`` **New in Django development version.** A tuple of133 processors to apply to the ``DjangoContext`` of134 this view's template. See the`DjangoContext docs`_132 ``processors`` A tuple of processors to apply to the 133 ``DjangoContext`` of this view's template. See the 134 `DjangoContext docs`_ 135 135 ======================= ================================================== 136 136 … … 151 151 Defaults to 15. 152 152 153 ``allow_empty`` **New in Django development version.** 154 If ``False`` and there are no objects to display, 153 ``allow_empty`` If ``False`` and there are no objects to display, 155 154 the view will raise a 404 instead of displaying 156 155 an empty index page. ``False`` is default. django/branches/magic-removal/docs/request_response.txt
r1873 r1904 152 152 a mutable ``QueryDict`` (one that was created via ``copy()``). 153 153 154 * ``__contains__(key)`` -- **New in Django development version.** Returns 155 ``True`` if the given key is set. This lets you do, e.g., 156 ``if "foo" in request.GET``. 154 * ``__contains__(key)`` -- Returns ``True`` if the given key is set. This 155 lets you do, e.g., ``if "foo" in request.GET``. 157 156 158 157 * ``get(key, default)`` -- Uses the same logic as ``__getitem__()`` above, … … 362 361 363 362 ``HttpResponsePermanentRedirect`` 364 **New in Django development version.***365 366 363 Like ``HttpResponseRedirect``, but it returns a permanent redirect (HTTP 367 364 status code 301) instead of a "found" redirect (status code 302). django/branches/magic-removal/docs/sessions.txt
r1866 r1904 31 31 32 32 * ``__contains__(key)`` 33 **New in Django development version.**Example: ``'fav_color' in request.session``33 Example: ``'fav_color' in request.session`` 34 34 35 35 * ``__getitem__(key)`` … … 178 178 request.session['foo']['bar'] = 'baz' 179 179 180 **Only available in Django development version.** To change this default 181 behavior, set the ``SESSION_SAVE_EVERY_REQUEST`` setting to ``True``. If 182 ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, Django will save the session to the 183 database on every single request. 180 To change this default behavior, set the ``SESSION_SAVE_EVERY_REQUEST`` setting 181 to ``True``. If ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, Django will save 182 the session to the database on every single request. 184 183 185 184 Note that the session cookie is only sent when a session has been created or … … 214 213 ------------------- 215 214 216 Default: ``'sessionid'`` (**Django development version.** Previous default was 217 ``'hotclub'``, which was deemed too pornish.) 215 Default: ``'sessionid'`` 218 216 219 217 The name of the cookie to use for sessions. This can be whatever you want. … … 223 221 224 222 Default: ``False`` 225 226 **Only available in Django development version.**227 223 228 224 Whether to save the session data on every request. If this is ``False`` django/branches/magic-removal/docs/settings.txt
r1810 r1904 526 526 ------------------- 527 527 528 Default: ``'sessionid'`` (**Django development version.** Previous default was 529 ``'hotclub'``, which was deemed too pornish.) 528 Default: ``'sessionid'`` 530 529 531 530 The name of the cookie to use for sessions. This can be whatever you want. … … 557 556 "django.core.context_processors.i18n") 558 557 559 **Only available in Django development version.**560 561 558 A tuple of callables that are used to populate the context in ``DjangoContext``. 562 559 These callables take a request object as their argument and return a dictionary … … 567 564 568 565 Default: ``False`` 569 570 **Only available in Django development version.**571 566 572 567 A boolean that turns on/off template debug mode. If this is ``True``, the fancy django/branches/magic-removal/docs/templates_python.txt
r1873 r1904 283 283 }, [ip_address_processor]) 284 284 285 Note: The concept of template-context processors is new in the Django286 development version. In Django 0.90, ``DjangoContext`` automatically populates287 the context with all of the values explained below, but it's not possible to288 add and remove processors.289 290 285 Here's what each of the default processors does: 291 286 … … 541 536 ------------------------------- 542 537 543 **This section applies to the Django development version.**544 545 538 Custom filters are just Python functions that take one or two arguments: 546 539 … … 601 594 Writing custom template tags 602 595 ---------------------------- 603 604 **This section applies to the Django development version.**605 596 606 597 Tags are more complex than filters, because tags can do anything. django/branches/magic-removal/docs/templates.txt
r1525 r1904 279 279 area in your admin to find the list of custom libraries in your installation. 280 280 281 **New in Django development version:** The ``{% load %}`` tag can take multiple 282 library names, separated by spaces.Example::281 The ``{% load %}`` tag can take multiple library names, separated by spaces. 282 Example:: 283 283 284 284 {% load comments i18n %} … … 500 500 include 501 501 ~~~~~~~ 502 503 **Only available in Django development version.**504 502 505 503 Loads a template and renders it with the current context. This is a way of django/branches/magic-removal/docs/tutorial01.txt
r1687 r1904 35 35 .. admonition:: Where should this code live? 36 36 37 If your background is in PHP, you're probably used to putting code under the38 Web server's document root (in a place such as ``/var/www``). With Django,39 you don't do that. It's not a good idea to put any of this Python code within40 your Web server's document root, because it risks the possibility that41 people may be able to view your code over the Web. That's not good for42 security.43 44 Put your code in some directory **outside** of the document root, such as45 ``/home/mycode``.37 If your background is in PHP, you're probably used to putting code under the 38 Web server's document root (in a place such as ``/var/www``). With Django, 39 you don't do that. It's not a good idea to put any of this Python code within 40 your Web server's document root, because it risks the possibility that 41 people may be able to view your code over the Web. That's not good for 42 security. 43 44 Put your code in some directory **outside** of the document root, such as 45 ``/home/mycode``. 46 46 47 47 A project is a collection of settings for an instance of Django -- including … … 51 51 myproject/ 52 52 __init__.py 53 apps/ 54 __init__.py 53 manage.py 55 54 settings.py 56 55 urls.py 57 56 58 First, edit ``myproject/settings.py``. It's a normal Python module with 59 module-level variables representing Django settings. Edit the file and change 60 these settings to match your database's connection parameters: 57 These files are: 58 59 * ``manage.py``: A command-line utility that lets you interact with this 60 Django project in various ways. 61 * ``settings.py``: Settings/configuration for this Django project. 62 * ``urls.py``: The URL declarations for this Django project; a "table of 63 contents" of your Django-powered site. 64 65 The development server 66 ---------------------- 67 68 Change into the ``myproject`` directory, if you haven't already, and run the 69 command ``python manage.py runserver``. You'll see the following output on the 70 command line:: 71 72 Validating models... 73 0 errors found. 74 75 Starting server on port 8000 with settings module 'myproject.settings'. 76 Go to http://127.0.0.1:8000/ for Django. 77 Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows). 78 79 You've started the Django development server, a lightweight, pure-Python Web 80 server that builds on the BaseHTTPServer included in Python's standard library. 81 We've included this with Django so you can develop things rapidly, without 82 having to deal with configuring Apache until you're ready for production. 83 84 DON'T use this server in anything resembling a production environment. It's 85 intended only for use while developing. 86 87 .. admonition:: Changing the port 88 89 By default, the ``runserver`` command starts the development server on port 90 8000. If you want to change the server's port, pass it as a command-line 91 argument:: 92 93 python manage.py runserver 8080 94 95 Now that the server's running, visit http://127.0.0.1:8000/ with your Web 96 browser. You'll see a "Welcome to Django" page, in pleasant, light-blue pastel. 97 It worked! 98 99 Database setup 100 -------------- 101 102 Now, edit ``settings.py``. It's a normal Python module with module-level 103 variables representing Django settings. Change these settings to match your 104 database's connection parameters: 61 105 62 106 * ``DATABASE_ENGINE`` -- Either 'postgresql', 'mysql' or 'sqlite3'. 63 107 More coming soon. 64 108 * ``DATABASE_NAME`` -- The name of your database, or the full (absolute) 65 path to the database file if you're using sqlite.66 * ``DATABASE_USER`` -- Your database username (not used for sqlite).67 * ``DATABASE_PASSWORD`` -- Your database password (not used for sqlite).109 path to the database file if you're using SQLite. 110 * ``DATABASE_USER`` -- Your database username (not used for SQLite). 111 * ``DATABASE_PASSWORD`` -- Your database password (not used for SQLite). 68 112 * ``DATABASE_HOST`` -- The host your database is on. Leave this as an 69 113 empty string if your database server is on the same physical machine 70 (not used for sqlite).114 (not used for SQLite). 71 115 72 116 .. admonition:: Note … … 76 120 database's interactive prompt. 77 121 78 Now, take a second to make sure ``myproject`` is on your Python path. You 79 can do this by copying ``myproject`` to Python's ``site-packages`` directory, 80 or you can do it by altering the ``PYTHONPATH`` environment variable. See the 81 `Python path documentation`_ for more information. If you opt to set the 82 ``PYTHONPATH`` environment variable, note that you'll need to set it to the 83 *parent* directory of ``myproject``. (You can test this by typing 84 "import myproject" into the Python interactive prompt.) 85 86 Run the following command:: 87 88 django-admin.py init --settings=myproject.settings 89 90 The ``django-admin.py`` utility generally needs to know which settings module 91 you're using. Here, we're doing that by specifying ``settings=`` on the command 92 line, but that can get tedious. If you don't want to type ``settings=`` each 93 time, you can set the ``DJANGO_SETTINGS_MODULE`` environment variable. Here's 94 how you do that in the Bash shell on Unix:: 95 96 export DJANGO_SETTINGS_MODULE=myproject.settings 97 98 On Windows, you'd use ``set`` instead:: 99 100 set DJANGO_SETTINGS_MODULE=myproject.settings 101 102 If you don't see any errors after running ``django-admin.py init``, you know it 103 worked. That command initialized your database with Django's core database 104 tables. If you're interested, run the command-line client for your database and 105 type ``\dt`` (PostgreSQL), ``SHOW TABLES;`` (MySQL), or ``.schema`` (SQLite) to 106 display the tables. 107 108 .. _`Python path documentation`: http://docs.python.org/tut/node8.html#SECTION008110000000000000000 122 Run the following command to initialize your database with Django's core 123 database tables:: 124 125 python manage.py init 126 127 If you don't see any errors, it worked. 128 129 If you're interested, run the command-line client for your database and type 130 ``\dt`` (PostgreSQL), ``SHOW TABLES;`` (MySQL), or ``.schema`` (SQLite) to 131 display the tables Django created. 132 133 .. admonition:: About those database tables 134 135 The tables created by ``manage.py init`` are for sessions, authentication 136 and other features Django provides. The next release of Django will have 137 a "lite" version of the ``init`` command that won't install any database 138 tables if you don't want them. 109 139 110 140 Creating models … … 112 142 113 143 Now that your environment -- a "project" -- is set up, you're set to start 114 doing work. (You won't have to take care of th isboring administrative stuff144 doing work. (You won't have to take care of that boring administrative stuff 115 145 again.) 116 146 117 Each application you write in Django -- e.g., a weblog system, a database of 118 public records or a simple poll app -- consists of a Python package, somewhere 119 on your Python path, that follows a certain convention. Django comes with a 147 Each application you write in Django consists of a Python package, somewhere 148 on your `Python path`_, that follows a certain convention. Django comes with a 120 149 utility that automatically generates the basic directory structure of an app, 121 150 so you can focus on writing code rather than creating directories. 122 151 123 In this tutorial, we'll create our poll app in the ``myproject/apps`` 124 directory, for simplicity. As a consequence, the app will be coupled to the 125 project -- that is, Python code within the poll app will refer to 126 ``myproject.apps.polls``. Later in this tutorial, we'll discuss decoupling 127 your apps for distribution. 128 129 To create your app, change into the ``myproject/apps`` directory and type this 130 command:: 131 132 django-admin.py startapp polls 133 134 (From now on, this tutorial will leave out the ``--settings`` parameter and 135 will assume you've either set your ``DJANGO_SETTINGS_MODULE`` environment 136 variable or included the ``--settings`` option in your call to the command.) 137 138 That'll create a directory structure like this:: 152 .. admonition:: Projects vs. apps 153 154 What's the difference between a project and an app? An app is a Web 155 application that does something -- e.g., a weblog system, a database of 156 public records or a simple poll app. A project is a collection of 157 configuration and apps for a particular Web site. A project can contain 158 multiple apps. An app can be in multiple projects. 159 160 In this tutorial, we'll create our poll app in the ``myproject`` directory, 161 for simplicity. As a consequence, the app will be coupled to the project -- 162 that is, Python code within the poll app will refer to ``myproject.polls``. 163 Later in this tutorial, we'll discuss decoupling your apps for distribution. 164 165 To create your app, make sure you're in the ``myproject`` directory and type 166 this command:: 167 168 python manage.py startapp polls 169 170 That'll create a directory ``polls``, which is laid out like this:: 139 171 140 172 polls/ … … 202 234 database relationships: many-to-ones, many-to-manys and one-to-ones. 203 235 236 .. _`Python path`: http://docs.python.org/tut/node8.html#SECTION008110000000000000000 204 237 .. _DRY Principle: http://c2.com/cgi/wiki?DontRepeatYourself 205 238 … … 210 243 is able to: 211 244 212 * Create a database schema (``CREATE TABLE`` statements) for this app.213 * Create a Python database-access API for accessing Poll and Choice objects.245 * Create a database schema (``CREATE TABLE`` statements) for this app. 246 * Create a Python database-access API for accessing Poll and Choice objects. 214 247 215 248 But first we need to tell our project that the ``polls`` app is installed. … … 217 250 .. admonition:: Philosophy 218 251 219 Django apps are "pluggable": You can use an app in multiple220 projects, and you can distribute apps, because they don't have to be tied to221 a givenDjango installation.222 223 Edit the myproject/settings.py file again, and change the ``INSTALLED_APPS``224 setting to include the string "myproject.apps.polls". So it'll look like this::252 Django apps are "pluggable": You can use an app in multiple projects, and 253 you can distribute apps, because they don't have to be tied to a given 254 Django installation. 255 256 Edit the ``settings.py`` file again, and change the ``INSTALLED_APPS`` setting 257 to include the string ``'myproject.polls'``. So it'll look like this:: 225 258 226 259 INSTALLED_APPS = ( 227 'myproject. apps.polls',260 'myproject.polls', 228 261 ) 229 262 230 (Don't forget the trailing comma because of Python's rules about single-value 231 tuples.) 232 233 Now Django knows myproject includes the polls app. Let's run another command:: 234 235 django-admin.py sql polls 236 237 (Note that it doesn't matter which directory you're in when you run this command.) 263 (Don't forget the trailing comma, because of Python's rule about single-value 264 tuples: Without a trailing comma, Python wouldn't know this was a tuple.) 265 266 Now Django knows ``myproject`` includes the ``polls`` app. Let's run another command:: 267 268 python manage.py sql polls 238 269 239 270 You should see the following (the CREATE TABLE SQL statements for the polls app):: … … 256 287 257 288 * Table names are automatically generated by combining the name of the app 258 ( polls) with a plural version of the object name (polls and choices). (You259 can override this behavior.)289 (``polls``) with a plural version of the object name (polls and choices). 290 (You can override this behavior.) 260 291 261 292 * Primary keys (IDs) are added automatically. (You can override this, too.) … … 266 297 * The foreign key relationship is made explicit by a ``REFERENCES`` statement. 267 298 268 * It's tailored to the database you're using, so database-specific field types269 such as ``auto_increment`` (MySQL), ``serial`` (PostgreSQL), or ``integer270 primary key`` (SQLite) are handled for you automatically. Same goes for271 quoting of field names -- e.g., using double quotes or single quotes. The272 author of this tutorial runs PostgreSQL, so the example output is in273 PostgreSQL syntax.299 * It's tailored to the database you're using, so database-specific field 300 types such as ``auto_increment`` (MySQL), ``serial`` (PostgreSQL), or 301 ``integer primary key`` (SQLite) are handled for you automatically. Same 302 goes for quoting of field names -- e.g., using double quotes or single 303 quotes. The author of this tutorial runs PostgreSQL, so the example 304 output is inPostgreSQL syntax. 274 305 275 306 If you're interested, also run the following commands: 276 307 277 * `` django-admin.py sqlinitialdata polls`` -- Outputs the initial-data308 * ``python manage.py sqlinitialdata polls`` -- Outputs the initial-data 278 309 inserts required for Django's admin framework. 279 310 280 * `` django-admin.py sqlclear polls`` -- Outputs the necessary ``DROP311 * ``python manage.py sqlclear polls`` -- Outputs the necessary ``DROP 281 312 TABLE`` statements for this app, according to which tables already exist 282 313 in your database (if any). 283 314 284 * `` django-admin.py sqlindexes polls`` -- Outputs the ``CREATE INDEX``315 * ``python manage.py sqlindexes polls`` -- Outputs the ``CREATE INDEX`` 285 316 statements for this app. 286 317 287 * `` django-admin.py sqlall polls`` -- A combination of 'sql' and318 * ``python manage.py sqlall polls`` -- A combination of 'sql' and 288 319 'sqlinitialdata'. 289 320 … … 294 325 automatically:: 295 326 296 django-admin.py install polls327 python manage.py install polls 297 328 298 329 Behind the scenes, all that command does is take the output of 299 `` django-admin.py sqlall polls`` and execute it in the database pointed-to by330 ``python manage.py sqlall polls`` and execute it in the database pointed-to by 300 331 your Django settings file. 301 332 302 Read the `django-admin.py documentation`_ for full information on what th is303 utility can do.333 Read the `django-admin.py documentation`_ for full information on what the 334 ``manage.py`` utility can do. 304 335 305 336 .. _django-admin.py documentation: http://www.djangoproject.com/documentation/django_admin/ … … 308 339 ==================== 309 340 310 Now, make sure your DJANGO_SETTINGS_MODULE environment variable is set (as 311 explained above), and open the Python interactive shell to play around with the 312 free Python API Django gives you:: 341 Now, let's hop into the interactive Python shell and play around with the free 342 API Django gives you. To invoke the Python shell, use this command:: 343 344 python manage.py shell 345 346 We're using this instead of simply typing "python", because ``manage.py`` sets 347 up the project's environment for you. "Setting up the environment" involves two 348 things: 349 350 * Putting ``myproject`` on ``sys.path``. For flexibility, several pieces of 351 Django refer to projects in Python dotted-path notation (e.g. 352 ``'myproject.polls.models'``). In order for this to work, the 353 ``myproject`` package has to be on ``sys.path``. 354 355 We've already seen one example of this: the ``INSTALLED_APPS`` setting is 356 a list of packages in dotted-path notation. 357 358 * Setting the ``DJANGO_SETTINGS_MODULE`` environment variable, which gives 359 Django the path to your ``settings.py`` file. 360 361 .. admonition:: Bypassing manage.py 362 363 If you'd rather not use ``manage.py``, no problem. Just make sure 364 ``myproject`` is at the root level on the Python path (i.e., 365 ``import myproject`` works) and set the ``DJANGO_SETTINGS_MODULE`` 366 environment variable to ``myproject.settings``. 367 368 For more information on all of this, see the `django-admin.py documentation`_. 369 370 Once you're in the shell, explore the database API:: 313 371 314 372 # Modules are dynamically created within django.models. … … 327 385 >>> p.save() 328 386 329 # Now it has an ID. 387 # Now it has an ID. Note that this might say "1L" instead of "1", depending 388 # on which database you're using. That's no biggie; it just means your 389 # database backend prefers to return integers as Python long integer 390 # objects. 330 391 >>> p.id 331 392 1 … … 376 437 ``datetime`` module from the Python standard library. 377 438 378 Let's jump back into the Python interactive shell:: 439 Let's jump back into the Python interactive shell by running 440 ``python manage.py shell`` again:: 379 441 380 442 >>> from django.models.polls import polls, choices django/branches/magic-removal/docs/tutorial02.txt
r1754 r1904 32 32 33 33 * Add ``"django.contrib.admin"`` to your ``INSTALLED_APPS`` setting. 34 * Run the command `` django-admin.py install admin``. This will create an34 * Run the command ``python manage.py install admin``. This will create an 35 35 extra database table that the admin needs. 36 36 * Edit your ``myproject/urls.py`` file and uncomment the line below … … 44 44 Run the following command to create a superuser account for your admin site:: 45 45 46 django-admin.py createsuperuser --settings=myproject.settings46 python manage.py createsuperuser 47 47 48 48 The script will prompt you for a username, e-mail address and password (twice). … … 51 51 ============================ 52 52 53 To make things easy, Django comes with a pure-Python Web server that builds on 54 the BaseHTTPServer included in Python's standard library. Let's start the 55 server and explore the admin site. 56 57 Just run the following command to start the server:: 58 59 django-admin.py runserver --settings=myproject.settings 60 61 It'll start a Web server running locally -- on port 8000, by default. If you 62 want to change the server's port, pass it as a command-line argument:: 63 64 django-admin.py runserver 8080 --settings=myproject.settings 65 66 DON'T use this server in anything resembling a production environment. It's 67 intended only for use while developing. 53 Let's start the development server and explore the admin site. 54 55 Recall from Tutorial 1 that you start the development server like so:: 56 57 python manage.py runserver 68 58 69 59 Now, open a Web browser and go to "/admin/" on your local domain -- e.g., … … 92 82 But where's our poll app? It's not displayed on the admin index page. 93 83 94 Just one thing to do: We need to specify in the `` polls.Poll`` model that Poll95 objects have an admin interface. Edit the ``myproject/ apps/polls/models/polls.py``84 Just one thing to do: We need to specify in the ``Poll`` model that ``Poll`` 85 objects have an admin interface. Edit the ``myproject/polls/models/polls.py`` 96 86 file and make the following change to add an inner ``Meta`` class with an 97 87 ``admin`` attribute:: … … 102 92 admin = meta.Admin() 103 93 104 The ``class Meta`` contains all non-field metadataabout this model.94 The ``class Meta`` contains all `non-field metadata`_ about this model. 105 95 106 96 Now reload the Django admin page to see your changes. Note that you don't have 107 97 to restart the development server -- it auto-reloads code. 98 99 .. _non-field metadata: http://www.djangoproject.com/documentation/model_api/#meta-options 108 100 109 101 Explore the free admin functionality … … 217 209 ====================== 218 210 219 OK, we have our Poll admin page. But a ``Poll`` has multiple ``Choices``, and the admin220 page doesn't display choices.211 OK, we have our Poll admin page. But a ``Poll`` has multiple ``Choices``, and 212 the admin page doesn't display choices. 221 213 222 214 Yet. 223 215 224 In this case, there are two ways to solve this problem. The first is to give 225 the ``Choice`` model its own ``admin`` attribute, just as we did with ``Poll``. 226 Here's whatthat would look like::216 There are two ways to solve this problem. The first is to give the ``Choice`` 217 model its own ``admin`` attribute, just as we did with ``Poll``. Here's what 218 that would look like:: 227 219 228 220 class Choice(meta.Model): … … 238 230 239 231 In that form, the "Poll" field is a select box containing every poll in the 240 database. In our case, only one poll exists at this point. 232 database. Django knows that a ``ForeignKey`` should be represented in the admin 233 as a ``<select>`` box. In our case, only one poll exists at this point. 241 234 242 235 Also note the "Add Another" link next to "Poll." Every object with a ForeignKey … … 364 357 That adds a search box at the top of the change list. When somebody enters 365 358 search terms, Django will search the ``question`` field. You can use as many 366 fields as you'd like -- although because it uses a LIKEquery behind the359 fields as you'd like -- although because it uses a ``LIKE`` query behind the 367 360 scenes, keep it reasonable, to keep your database happy. 368 361 … … 445 438 446 439 Django offers another shortcut in this department. Run the command 447 `` django-admin.py adminindex polls`` to get a chunk of template code for440 ``python manage.py adminindex polls`` to get a chunk of template code for 448 441 inclusion in the admin index template. It's a useful starting point. 449 442 django/branches/magic-removal/docs/tutorial03.txt
r1291 r1904 63 63 For more details on URLconfs, see the `URLconf documentation`_. 64 64 65 When you ran `` django-admin.py startproject myproject`` at the beginning of65 When you ran ``python manage.py startproject myproject`` at the beginning of 66 66 Tutorial 1, it created a default URLconf in ``myproject/urls.py``. It also 67 67 automatically set your ``ROOT_URLCONF`` setting to point at that file:: … … 74 74 75 75 urlpatterns = patterns('', 76 (r'^polls/$', 'myproject. apps.polls.views.index'),77 (r'^polls/( ?P<poll_id>\d+)/$', 'myproject.apps.polls.views.detail'),78 (r'^polls/( ?P<poll_id>\d+)/results/$', 'myproject.apps.polls.views.results'),79 (r'^polls/( ?P<poll_id>\d+)/vote/$', 'myproject.apps.polls.views.vote'),76 (r'^polls/$', 'myproject.polls.views.index'), 77 (r'^polls/(\d+)/$', 'myproject.polls.views.detail'), 78 (r'^polls/(\d+)/results/$', 'myproject.polls.views.results'), 79 (r'^polls/(\d+)/vote/$', 'myproject.polls.views.vote'), 80 80 ) 81 81 … … 84 84 by the ``ROOT_URLCONF`` setting. It finds the variable named ``urlpatterns`` 85 85 and traverses the regular expressions in order. When it finds a regular 86 expression that matches -- ``r'^polls/( ?P<poll_id>\d+)/$'`` -- it loads the87 associated Python package/module: ``myproject. apps.polls.views.detail``. That88 corresponds to the function ``detail()`` in ``myproject/ apps/polls/views.py``.86 expression that matches -- ``r'^polls/(\d+)/$'`` -- it loads the 87 associated Python package/module: ``myproject.polls.views.detail``. That 88 corresponds to the function ``detail()`` in ``myproject/polls/views.py``. 89 89 Finally, it calls that ``detail()`` function like so:: 90 90 91 91 detail(request=<HttpRequest object>, poll_id='23') 92 92 93 The ``poll_id='23'`` part comes from ``( ?P<poll_id>\d+)``. Using94 ``(?P<name>pattern)`` "captures" the text matched by ``pattern`` and sends it95 as a keyword argumentto the view function.93 The ``poll_id='23'`` part comes from ``(\d+)``. Using parenthesis around a 94 pattern "captures" the text matched by that pattern and sends it as an argument 95 to the view function. 96 96 97 97 Because the URL patterns are regular expressions, there really is no limit on … … 100 100 something like this:: 101 101 102 (r'^polls/latest\.php$', 'myproject. apps.polls.views.index'),102 (r'^polls/latest\.php$', 'myproject.polls.views.index'), 103 103 104 104 But, don't do that. It's silly. … … 129 129 Fire up the Django development Web server:: 130 130 131 django-admin.py runserver --settings=myproject.settings&nb
