Changeset 956
- Timestamp:
- 10/19/05 10:47:26 (3 years ago)
- Files:
-
- django/branches/i18n/django/conf/admin_media (deleted)
- django/branches/i18n/django/conf/admin_templates (deleted)
- django/branches/i18n/django/conf/project_template/settings/__init__.py (deleted)
- django/branches/i18n/django/conf/project_template/settings/main.py (deleted)
- django/branches/i18n/django/conf/project_template/settings.py (added)
- django/branches/i18n/django/conf/project_template/settings/urls (deleted)
- django/branches/i18n/django/conf/project_template/urls.py (added)
- django/branches/i18n/django/conf/urls/admin.py (deleted)
- django/branches/i18n/django/contrib/admin/media (added)
- django/branches/i18n/django/contrib/admin/media/css (added)
- django/branches/i18n/django/contrib/admin/media/css/base.css (added)
- django/branches/i18n/django/contrib/admin/media/css/changelists.css (added)
- django/branches/i18n/django/contrib/admin/media/css/global.css (added)
- django/branches/i18n/django/contrib/admin/media/img (added)
- django/branches/i18n/django/contrib/admin/media/img/admin (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/arrow-down.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/arrow-up.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/changelist-bg.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/chooser-bg.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/chooser_stacked-bg.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/default-bg.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/default-bg-reverse.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/icon_addlink.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/icon_alert.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/icon_calendar.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/icon_changelink.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/icon_clock.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/icon_deletelink.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/icon_error.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/icon-no.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/icon_searchbox.png (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/icon_success.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/icon-yes.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/nav-bg.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/nav-bg-grabber.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/nav-bg-reverse.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/selector-addall.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/selector-add.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/selector-removeall.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/selector-remove.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/selector-search.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/selector_stacked-add.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/selector_stacked-remove.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/tool-left.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/tool-left_over.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/tool-right.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/tool-right_over.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/tooltag-add.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/tooltag-add_over.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/tooltag-arrowright.gif (added)
- django/branches/i18n/django/contrib/admin/media/img/admin/tooltag-arrowright_over.gif (added)
- django/branches/i18n/django/contrib/admin/media/js (added)
- django/branches/i18n/django/contrib/admin/media/js/admin (added)
- django/branches/i18n/django/contrib/admin/media/js/admin/CollapsedFieldsets.js (added)
- django/branches/i18n/django/contrib/admin/media/js/admin/DateTimeShortcuts.js (added)
- django/branches/i18n/django/contrib/admin/media/js/admin/ordering.js (added)
- django/branches/i18n/django/contrib/admin/media/js/admin/RelatedObjectLookups.js (added)
- django/branches/i18n/django/contrib/admin/media/js/calendar.js (added)
- django/branches/i18n/django/contrib/admin/media/js/core.js (added)
- django/branches/i18n/django/contrib/admin/media/js/dateparse.js (added)
- django/branches/i18n/django/contrib/admin/media/js/getElementsBySelector.js (added)
- django/branches/i18n/django/contrib/admin/media/js/SelectBox.js (added)
- django/branches/i18n/django/contrib/admin/media/js/SelectFilter2.js (added)
- django/branches/i18n/django/contrib/admin/media/js/SelectFilter.js (added)
- django/branches/i18n/django/contrib/admin/media/js/timeparse.js (added)
- django/branches/i18n/django/contrib/admin/media/js/urlify.js (added)
- django/branches/i18n/django/contrib/admin/models (added)
- django/branches/i18n/django/contrib/admin/models/admin.py (added)
- django/branches/i18n/django/contrib/admin/models/__init__.py (added)
- django/branches/i18n/django/contrib/admin/templates/admin/404.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin/500.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin/base.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin/base_site.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin/delete_confirmation.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin_doc/bookmarklets.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin_doc/index.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin_doc/missing_docutils.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin_doc/model_detail.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin_doc/model_index.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin_doc/template_detail.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin_doc/template_filter_index.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin_doc/template_tag_index.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin_doc/view_detail.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin_doc/view_index.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin/index.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin/login.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin/object_history.html (added)
- django/branches/i18n/django/contrib/admin/templates/admin/template_validator.html (added)
- django/branches/i18n/django/contrib/admin/templates/registration/logged_out.html (added)
- django/branches/i18n/django/contrib/admin/templates/registration/password_change_done.html (added)
- django/branches/i18n/django/contrib/admin/templates/registration/password_change_form.html (added)
- django/branches/i18n/django/contrib/admin/templates/registration/password_reset_done.html (added)
- django/branches/i18n/django/contrib/admin/templates/registration/password_reset_email.html (added)
- django/branches/i18n/django/contrib/admin/templates/registration/password_reset_form.html (added)
- django/branches/i18n/django/contrib/admin/templatetags (added)
- django/branches/i18n/django/contrib/admin/templatetags/adminapplist.py (added)
- django/branches/i18n/django/contrib/admin/templatetags/adminmedia.py (added)
- django/branches/i18n/django/contrib/admin/templatetags/__init__.py (added)
- django/branches/i18n/django/contrib/admin/templatetags/log.py (added)
- django/branches/i18n/django/contrib/admin/urls/admin.py (added)
- django/branches/i18n/django/contrib/admin/views/main.py (modified) (6 diffs)
- django/branches/i18n/django/contrib/admin/views/template.py (modified) (1 diff)
- django/branches/i18n/django/core/db/backends/ado_mssql.py (modified) (2 diffs)
- django/branches/i18n/django/core/handlers/base.py (modified) (1 diff)
- django/branches/i18n/django/core/management.py (modified) (3 diffs)
- django/branches/i18n/django/core/servers/basehttp.py (modified) (1 diff)
- django/branches/i18n/django/middleware/admin.py (deleted)
- django/branches/i18n/django/middleware/cache.py (modified) (1 diff)
- django/branches/i18n/django/models/auth.py (modified) (1 diff)
- django/branches/i18n/django/templatetags/adminapplist.py (deleted)
- django/branches/i18n/django/templatetags/adminmedia.py (deleted)
- django/branches/i18n/django/templatetags/log.py (deleted)
- django/branches/i18n/docs/django-admin.txt (modified) (1 diff)
- django/branches/i18n/docs/faq.txt (modified) (1 diff)
- django/branches/i18n/docs/middleware.txt (modified) (1 diff)
- django/branches/i18n/docs/model-api.txt (modified) (1 diff)
- django/branches/i18n/docs/modpython.txt (modified) (4 diffs)
- django/branches/i18n/docs/settings.txt (modified) (3 diffs)
- django/branches/i18n/docs/tutorial01.txt (modified) (5 diffs)
- django/branches/i18n/docs/tutorial02.txt (modified) (6 diffs)
- django/branches/i18n/docs/tutorial03.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/i18n/django/contrib/admin/views/main.py
r932 r956 7 7 from django.core.extensions import DjangoContext as Context 8 8 from django.core.extensions import get_object_or_404, render_to_response 9 from django.models.a uthimport log9 from django.models.admin import log 10 10 from django.utils.html import strip_tags 11 11 from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect … … 50 50 51 51 def index(request): 52 return render_to_response(' index', {'title': 'Site administration'}, context_instance=Context(request))52 return render_to_response('admin/index', {'title': 'Site administration'}, context_instance=Context(request)) 53 53 index = staff_member_required(index) 54 54 … … 267 267 pass # Invalid argument to "list_filter" 268 268 269 raw_template = ['{% extends " base_site" %}\n']269 raw_template = ['{% extends "admin/base_site" %}\n'] 270 270 raw_template.append('{% block bodyclass %}change-list{% endblock %}\n') 271 271 if not is_popup: … … 539 539 ordered_objects = opts.get_ordered_objects()[:] 540 540 auto_populated_fields = [f for f in opts.fields if f.prepopulate_from] 541 t = ['{% extends " base_site" %}\n']541 t = ['{% extends "admin/base_site" %}\n'] 542 542 t.append('{% block extrahead %}') 543 543 … … 1088 1088 request.user.add_message('The %s "%s" was deleted successfully.' % (opts.verbose_name, obj_repr)) 1089 1089 return HttpResponseRedirect("../../") 1090 return render_to_response(' delete_confirmation_generic', {1090 return render_to_response('admin/delete_confirmation', { 1091 1091 "title": "Are you sure?", 1092 1092 "object_name": opts.verbose_name, … … 1103 1103 # If no history was found, see whether this object even exists. 1104 1104 obj = get_object_or_404(mod, pk=object_id) 1105 return render_to_response('admin _object_history', {1105 return render_to_response('admin/object_history', { 1106 1106 'title': 'Change history: %r' % obj, 1107 1107 'action_list': action_list, django/branches/i18n/django/contrib/admin/views/template.py
r932 r956 24 24 if not errors: 25 25 request.user.add_message('The template is valid.') 26 return render_to_response(' template_validator', {26 return render_to_response('admin/template_validator', { 27 27 'title': 'Template validator', 28 28 'form': formfields.FormWrapper(manipulator, new_data, errors), django/branches/i18n/django/core/db/backends/ado_mssql.py
r886 r956 103 103 104 104 def get_random_function_sql(): 105 # TODO: This is a guess. Make sure this is correct. 106 return "RANDOM()" 105 return "RAND()" 106 107 def get_table_list(cursor): 108 raise NotImplementedError 107 109 108 110 def get_relations(cursor, table_name): … … 152 154 'USStateField': 'varchar(2)', 153 155 } 156 157 DATA_TYPES_REVERSE = {} django/branches/i18n/django/core/handlers/base.py
r886 r956 75 75 if response: 76 76 return response 77 raise e77 raise 78 78 79 79 # Complain if the view returned None (a common error). django/branches/i18n/django/core/management.py
r844 r956 18 18 # which has been installed. 19 19 PROJECT_TEMPLATE_DIR = os.path.join(django.__path__[0], 'conf', '%s_template') 20 ADMIN_TEMPLATE_DIR = os.path.join(django.__path__[0], 'conf', 'admin_templates')21 20 22 21 def _get_packages_insert(app_label): … … 143 142 cursor.execute("SELECT id FROM content_types WHERE package = %s", [app_label]) 144 143 for row in cursor.fetchall(): 145 output.append("DELETE FROM auth_admin_log WHERE content_type_id = %s;" % row[0])144 output.append("DELETE FROM django_admin_log WHERE content_type_id = %s;" % row[0]) 146 145 147 146 # Close database connection explicitly, in case this output is being piped … … 379 378 from random import choice 380 379 _start_helper('project', project_name, directory) 381 # Populate TEMPLATE_DIRS for the admin templates, based on where Django is382 # installed.383 admin_settings_file = os.path.join(directory, project_name, 'settings', 'admin.py')384 settings_contents = open(admin_settings_file, 'r').read()385 fp = open(admin_settings_file, 'w')386 settings_contents = re.sub(r'(?s)\b(TEMPLATE_DIRS\s*=\s*\()(.*?)\)', "\\1\n r%r,\\2)" % ADMIN_TEMPLATE_DIR, settings_contents)387 fp.write(settings_contents)388 fp.close()389 380 # Create a random SECRET_KEY hash, and put it in the main settings. 390 main_settings_file = os.path.join(directory, project_name, 'settings ', 'main.py')381 main_settings_file = os.path.join(directory, project_name, 'settings.py') 391 382 settings_contents = open(main_settings_file, 'r').read() 392 383 fp = open(main_settings_file, 'w') django/branches/i18n/django/core/servers/basehttp.py
r575 r956 603 603 import django 604 604 self.application = application 605 self.media_dir = django.__path__[0] + '/con f/admin_media'605 self.media_dir = django.__path__[0] + '/contrib/admin/media' 606 606 self.media_url = settings.ADMIN_MEDIA_PREFIX 607 607 django/branches/i18n/django/middleware/cache.py
r844 r956 53 53 def process_response(self, request, response): 54 54 "Sets the cache, if needed." 55 if not request._cache_update_cache:55 if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache: 56 56 # We don't need to update the cache, just return. 57 57 return response django/branches/i18n/django/models/auth.py
r912 r956 184 184 def __repr__(self): 185 185 return self.message 186 187 class META:188 verbose_name = _('Message')189 verbose_name_plural = _('Messages')190 191 class LogEntry(meta.Model):192 action_time = meta.DateTimeField(_('action time'), auto_now=True)193 user = meta.ForeignKey(User)194 content_type = meta.ForeignKey(core.ContentType, blank=True, null=True) # TODO: content_type_id name?195 object_id = meta.TextField(_('object id'), blank=True, null=True)196 object_repr = meta.CharField(_('object repr'), maxlength=200)197 action_flag = meta.PositiveSmallIntegerField(_('action flag'))198 change_message = meta.TextField(blank=True)199 class META:200 module_name = 'log'201 verbose_name = _('log entry')202 verbose_name_plural = _('log entries')203 db_table = 'auth_admin_log'204 ordering = ('-action_time',)205 module_constants = {206 'ADDITION': 1,207 'CHANGE': 2,208 'DELETION': 3,209 }210 211 def __repr__(self):212 return str(self.action_time)213 214 def is_addition(self):215 return self.action_flag == ADDITION216 217 def is_change(self):218 return self.action_flag == CHANGE219 220 def is_deletion(self):221 return self.action_flag == DELETION222 223 def get_edited_object(self):224 "Returns the edited object represented by this log entry"225 return self.get_content_type().get_object_for_this_type(pk=self.object_id)226 227 def get_admin_url(self):228 """229 Returns the admin URL to edit the object represented by this log entry.230 This is relative to the Django admin index page.231 """232 return "%s/%s/%s/" % (self.get_content_type().package, self.get_content_type().python_module_name, self.object_id)233 234 def _module_log_action(user_id, content_type_id, object_id, object_repr, action_flag, change_message=''):235 e = LogEntry(None, None, user_id, content_type_id, object_id, object_repr[:200], action_flag, change_message)236 e.save()django/branches/i18n/docs/django-admin.txt
r910 r956 193 193 Example usage:: 194 194 195 django-admin.py init --settings= 'myproject.settings.main'195 django-admin.py init --settings=myproject.settings 196 196 197 197 Explicitly specifies the settings module to use. The settings module should be 198 in Python path syntax, e.g. "myproject.settings .main". If this isn't provided,198 in Python path syntax, e.g. "myproject.settings". If this isn't provided, 199 199 ``django-admin.py`` will use the DJANGO_SETTINGS_MODULE environment variable. 200 200 django/branches/i18n/docs/faq.txt
r653 r956 349 349 to match your domain. For example, if you're going to 350 350 "http://www.mysite.com/admin/" in your browser, in 351 "myproject.settings.admin" you should set ``SESSION_COOKIE_DOMAIN = 352 'www.mysite.com'``. 351 "myproject.settings" you should set ``SESSION_COOKIE_DOMAIN = 'www.mysite.com'``. 353 352 354 353 * Some browsers (Firefox?) don't like to accept cookies from domains that django/branches/i18n/docs/middleware.txt
r886 r956 28 28 ) 29 29 30 The default admin site has the following ``MIDDLEWARE_CLASSES`` set::31 32 MIDDLEWARE_CLASSES = (33 "django.middleware.sessions.SessionMiddleware",34 "django.middleware.admin.AdminUserRequired",35 "django.middleware.common.CommonMiddleware",36 )37 38 30 Django applies middleware in the order it's defined in ``MIDDLEWARE_CLASSES``. 39 31 40 For a regular (i.e., non-admin) Django installation, no middleware is required, 41 but it's strongly suggested that you use ``CommonMiddleware``. For a Django 42 admin site, ``SessionMiddleware`` and ``AdminUserRequired`` (in that order) are 43 required. 32 A Django installation doesn't require any middleware -- e.g., 33 ``MIDDLEWARE_CLASSES`` can be empty, if you'd like -- but it's strongly 34 suggested that you use ``CommonMiddleware``. 44 35 45 36 Available middleware 46 37 ==================== 47 48 django.middleware.admin.AdminUserRequired49 -----------------------------------------50 51 Limits site access to valid users with the ``is_staff`` flag set. This is52 required by Django's admin, and this middleware requires ``SessionMiddleware``.53 38 54 39 django.middleware.cache.CacheMiddleware django/branches/i18n/docs/model-api.txt
r898 r956 250 250 The admin represents this as an ``<input type="file">`` (a file-upload widget). 251 251 252 Using a ` FieldField` or an ``ImageField`` (see below) in a model takes a few252 Using a ``FileField` or an ``ImageField`` (see below) in a model takes a few 253 253 steps: 254 254 django/branches/i18n/docs/modpython.txt
r853 r956 26 26 SetHandler python-program 27 27 PythonHandler django.core.handlers.modpython 28 SetEnv DJANGO_SETTINGS_MODULE myproject.settings .main28 SetEnv DJANGO_SETTINGS_MODULE myproject.settings 29 29 PythonDebug On 30 30 </Location> 31 31 32 ...and replace ``myproject.settings.main`` with the Python path to your 33 settings file. 32 ...and replace ``myproject.settings`` with the Python path to your settings file. 34 33 35 34 This tells Apache: "Use mod_python for any URL at or under '/mysite/', using the … … 56 55 time you make changes to your Python code. 57 56 58 Here's a template for an admin configuration::59 60 <Location "/admin/">61 SetHandler python-program62 PythonHandler django.core.handlers.modpython63 SetEnv DJANGO_SETTINGS_MODULE myproject.settings.admin64 PythonDebug On65 </Location>66 67 The only thing different here is the ``DJANGO_SETTINGS_MODULE``.68 69 57 Multiple Django installations on the same Apache 70 58 ================================================ … … 78 66 ServerName www.example.com 79 67 # ... 80 SetEnv DJANGO_SETTINGS_MODULE myproject.settings .main68 SetEnv DJANGO_SETTINGS_MODULE myproject.settings 81 69 </VirtualHost> 82 70 83 71 <VirtualHost *> 84 ServerName admin.example.com72 ServerName www2.example.com 85 73 # ... 86 SetEnv DJANGO_SETTINGS_MODULE myproject. settings.admin74 SetEnv DJANGO_SETTINGS_MODULE myproject.other_settings 87 75 </VirtualHost> 88 76 … … 96 84 # ... 97 85 <Location "/something"> 98 SetEnv DJANGO_SETTINGS_MODULE myproject.settings .main99 PythonInterpreter myproject _main86 SetEnv DJANGO_SETTINGS_MODULE myproject.settings 87 PythonInterpreter myproject 100 88 </Location> 101 89 102 <Location "/ admin">103 SetEnv DJANGO_SETTINGS_MODULE myproject. settings.admin104 PythonInterpreter myproject_ admin90 <Location "/otherthing"> 91 SetEnv DJANGO_SETTINGS_MODULE myproject.other_settings 92 PythonInterpreter myproject_other 105 93 </Location> 106 94 </VirtualHost> django/branches/i18n/docs/settings.txt
r910 r956 35 35 36 36 The value of ``DJANGO_SETTINGS_MODULE`` should be in Python path syntax, e.g. 37 ``"myproject.settings .main"``. Note that the settings module should be on the37 ``"myproject.settings"``. Note that the settings module should be on the 38 38 Python `import search path`_. 39 39 … … 48 48 Example (Unix Bash shell):: 49 49 50 export DJANGO_SETTINGS_MODULE=myproject.settings .main50 export DJANGO_SETTINGS_MODULE=myproject.settings 51 51 django-admin.py runserver 52 52 53 53 Example (Windows shell):: 54 54 55 set DJANGO_SETTINGS_MODULE=myproject.settings .main55 set DJANGO_SETTINGS_MODULE=myproject.settings 56 56 django-admin.py runserver 57 57 58 58 Use the ``--settings`` command-line argument to specify the settings manually:: 59 59 60 django-admin.py runserver --settings=myproject.settings .main60 django-admin.py runserver --settings=myproject.settings 61 61 62 62 .. _django-admin.py: http://www.djangoproject.com/documentation/django_admin/ … … 71 71 SetHandler python-program 72 72 PythonHandler django.core.handlers.modpython 73 SetEnv DJANGO_SETTINGS_MODULE myproject.settings .main73 SetEnv DJANGO_SETTINGS_MODULE myproject.settings 74 74 </Location> 75 75 django/branches/i18n/docs/tutorial01.txt
r775 r956 41 41 apps/ 42 42 __init__.py 43 settings/ 44 __init__.py 45 admin.py 46 main.py 47 urls/ 48 __init__.py 49 admin.py 50 main.py 51 52 First, edit ``myproject/settings/main.py``. It's a normal Python module with 43 settings.py 44 urls.py 45 46 First, edit ``myproject/settings.py``. It's a normal Python module with 53 47 module-level variables representing Django settings. Edit the file and change 54 48 these settings to match your database's connection parameters: … … 70 64 database's interactive prompt. 71 65 72 Also, note that MySQL and sqlite support is a recent development, and Django73 hasn't been comprehensively tested with either database. If you find any74 bugs in those bindings, please file them in `Django's ticket system`_ so we75 can fix them immediately.76 77 66 Now, take a second to make sure ``myproject`` is on your Python path. You 78 67 can do this by copying ``myproject`` to Python's ``site-packages`` directory, … … 85 74 Run the following command:: 86 75 87 django-admin.py init --settings=myproject.settings .main76 django-admin.py init --settings=myproject.settings 88 77 89 78 The ``django-admin.py`` utility generally needs to know which settings module … … 93 82 how you do that in the Bash shell on Unix:: 94 83 95 export DJANGO_SETTINGS_MODULE=myproject.settings .main84 export DJANGO_SETTINGS_MODULE=myproject.settings 96 85 97 86 On Windows, you'd use ``set`` instead:: 98 87 99 set DJANGO_SETTINGS_MODULE=myproject.settings .main88 set DJANGO_SETTINGS_MODULE=myproject.settings 100 89 101 90 If you don't see any errors after running ``django-admin.py init``, you know it … … 222 211 a given Django installation. 223 212 224 Edit the myproject/settings /main.py file again, and change the ``INSTALLED_APPS``213 Edit the myproject/settings.py file again, and change the ``INSTALLED_APPS`` 225 214 setting to include the string "myproject.apps.polls". So it'll look like this:: 226 215 django/branches/i18n/docs/tutorial02.txt
r596 r956 25 25 managers. 26 26 27 Activate the admin site 28 ======================= 29 30 The Django admin site is not activated by default -- it's an opt-in thing. To 31 activate the admin site for your installation, do these three things: 32 33 * Add ``"django.contrib.admin"`` to your ``INSTALLED_APPS`` setting. 34 * Run the command ``django-admin.py install admin``. This will create an 35 extra database table that the admin needs. 36 * Edit your ``myproject.urls`` file and uncomment the line below 37 "Uncomment this for admin:". This file is a URLconf; we'll dig into 38 URLconfs in the next tutorial. For now, all you need to know is that it 39 maps URL roots to applications. 40 27 41 Create a user account 28 42 ===================== … … 30 44 Run the following command to create a superuser account for your admin site:: 31 45 32 django-admin.py createsuperuser --settings="myproject.settings.main" 33 34 (Note: You can use either "myproject.settings.main" or "myproject.settings.admin" 35 here. They both reference the same database.) 46 django-admin.py createsuperuser --settings=myproject.settings 36 47 37 48 The script will prompt you for a username, e-mail address and password (twice). … … 46 57 Just run the following command to start the server:: 47 58 48 django-admin.py runserver --settings= "myproject.settings.admin"59 django-admin.py runserver --settings=myproject.settings 49 60 50 61 It'll start a Web server running locally -- on port 8000, by default. If you 51 62 want to change the server's port, pass it as a command-line argument:: 52 63 53 django-admin.py runserver 8080 --settings= "myproject.settings.admin"64 django-admin.py runserver 8080 --settings=myproject.settings 54 65 55 66 DON'T use this server in anything resembling a production environment. It's 56 67 intended only for use while developing. 57 68 58 Now, open a Web browser and go to "/admin/" on your domain. You should see the59 admin's login screen:69 Now, open a Web browser and go to "/admin/" on your local domain -- e.g., 70 http://127.0.0.1:8000/admin/. You should see the admin's login screen: 60 71 61 72 .. image:: http://media.djangoproject.com/img/doc/tutorial/admin01.png 62 73 :alt: Django admin login screen 63 74 64 .. admonition:: Note65 66 If you get an error telling you that the URL 'admin/' didn't match any of67 your URLconf entries, you most likely used ``myproject.settings.main``68 instead of ``myproject.settings.admin``.69 70 75 Enter the admin site 71 76 ==================== 72 77 73 Now, try logging in. 74 75 If it didn't work, read the `"I can't log in" questions`_ in the FAQ. 76 77 If it worked, you should see the Django admin index page: 78 Now, try logging in. You should see the Django admin index page: 78 79 79 80 .. image:: http://media.djangoproject.com/img/doc/tutorial/admin02t.png … … 382 383 ================================= 383 384 384 Clearly having "Django administration" and "example.com" at the top of each385 Clearly, having "Django administration" and "example.com" at the top of each 385 386 admin page is ridiculous. It's just placeholder text. 386 387 387 That's easy to change, though, using Django's template system. 388 389 Open your admin settings file and look at the ``TEMPLATE_DIRS`` setting. 390 ``TEMPLATE_DIRS`` is a tuple of filesystem directories to check when loading 391 Django templates. It's a search path. 392 393 The ``django-admin.py startproject`` command automatically prepopulated 394 this setting with the location of Django's default admin templates, according 395 to where you have Django installed. But let's add an extra line to 396 ``TEMPLATE_DIRS`` so that it checks a custom directory first, before checking 397 the default admin template directory:: 388 That's easy to change, though, using Django's template system. The Django admin 389 is powered by Django itself, and its interfaces use Django's own template 390 system. (How meta!) 391 392 Open your settings file (``myproject/settings.py``, remember) and look at the 393 ``TEMPLATE_DIRS`` setting. ``TEMPLATE_DIRS`` is a tuple of filesystem 394 directories to check when loading Django templates. It's a search path. 395 396 By default, ``TEMPLATE_DIRS`` is empty. So, let's add a line to it, to tell 397 Django where our templates live:: 398 398 399 399 TEMPLATE_DIRS = ( 400 "/home/mytemplates/admin", 401 "/usr/lib/python2.3/site-packages/django/conf/admin_templates", 400 "/home/mytemplates", # Change this to your own directory. 402 401 ) 403 402 404 Again, note that you should edit the admin settings file, not the main settings 405 file. That's because we're dealing with admin-site templates. 406 407 Now copy the template ``base_site.html`` from within the default Django admin 408 template directory, into ``/home/mytemplates/admin`` (or wherever you're 409 putting your custom admin templates). Edit the file and replace the generic 410 Django stuff with your own site's name as you see fit. 403 Now copy the template ``admin/base_site.html`` from within the default Django 404 admin template directory (``django/contrib/admin/templates``) into an ``admin`` 405 subdirectory of whichever directory you're using in ``TEMPLATE_DIRS``. For 406 example, if your ``TEMPLATE_DIRS`` includes ``"/home/mytemplates"``, as above, 407 then copy ``django/contrib/admin/templates/admin/base_site.html`` to 408 ``/home/mytemplates/admin/base_site.html``. 409 410 Then, just edit the file and replace the generic Django text with your own 411 site's name and URL as you see fit. 411 412 412 413 Note that any of Django's default admin templates can be overridden. To … … 415 416 changes. 416 417 418 Astute readers will ask: But if ``TEMPLATE_DIRS`` was empty by default, how was 419 Django finding the default admin templates? The answer is that, by default, 420 Django automatically looks for a ``templates/`` subdirectory within each app 421 package, for use as a fallback. See the `loader types documentation`_ for full 422 information. 423 424 .. _loader types documentation: http://www.djangoproject.com/documentation/templates_python/#loader-types 425 417 426 Customize the admin index page 418 427 ============================== … … 426 435 most important page of the admin, and it should be easy to use. 427 436 428 The template to customize is `` index.html``. (Do the same as with429 `` base_site.html`` in the previous section -- copy it from the default directory430 to your custom template directory.) Edit the file, and you'll see it uses a 431 template tag called ``{% get_admin_app_list as app_list %}``. That's the magic 432 that retrieves every installed Django app. Instead of using that, you can437 The template to customize is ``admin/index.html``. (Do the same as with 438 ``admin/base_site.html`` in the previous section -- copy it from the default 439 directory to your custom template directory.) Edit the file, and you'll see it 440 uses a template tag called ``{% get_admin_app_list as app_list %}``. That's the 441 magic that retrieves every installed Django app. Instead of using that, you can 433 442 hard-code links to object-specific admin pages in whatever way you think is 434 443 best. django/branches/i18n/docs/tutorial03.txt
r869 r956 63 63 64 64 When you ran ``django-admin.py startproject myproject`` at the beginning of 65 Tutorial 1, it created a default URLconf in ``myproject/ settings/urls/main.py``.66 It alsoautomatically set your ``ROOT_URLCONF`` setting to point at that file::67 68 ROOT_URLCONF = 'myproject. settings.urls.main'69 70 Time for an example. Edit ``myproject/ settings/urls/main.py`` so it looks like65 Tutorial 1, it created a default URLconf in ``myproject/urls.py``. It also 66 automatically set your ``ROOT_URLCONF`` setting to point at that file:: 67 68 ROOT_URLCONF = 'myproject.urls' 69 70 Time for an example. Edit ``myproject/urls.py`` so it looks like 71 71 this:: 72 72 … … 85 85 and traverses the regular expressions in order. When it finds a regular 86 86 expression that matches -- ``r'^polls/(?P<poll_id>\d+)/$'`` -- it loads the 87 associated Python package/module: ``myproject. polls.views.polls.detail``. That88 corresponds to the function ``detail()`` in ``myproject/ polls/views/polls.py``.87 associated Python package/module: ``myproject.apps.polls.views.polls.detail``. That 88 corresponds to the function ``detail()`` in ``myproject/apps/polls/views/polls.py``. 89 89 Finally, it calls that ``detail()`` function like so:: 90 90 … … 123 123 Fire up the Django development Web server:: 124 124 125 django-admin.py runserver --settings="myproject.settings.main" 126 127 (If you're coming here straight from Tutorial 2, note that we're now running 128 the server with ``--settings=myproject.settings.main`` instead of 129 ``--settings=myproject.settings.admin``. You'll need to restart the server to 130 change the ``settings`` parameter.) 125 django-admin.py runserver --settings=myproject.settings 131 126 132 127 Now go to "http://localhost:8000/polls/" on your domain in your Web browser. … … 414 409 coupled to the Django settings: The URLconf. 415 410 416 We've been editing the URLs in ``myproject/settings/urls/main.py``, but the 417 URL design of an app is specific to the app, not to the Django installation -- 418 so let's move the URLs within the app directory. 419 420 Create a directory ``myproject/apps/polls/urls/``, and put a blank file called 421 ``__init__.py`` into it. (The ``__init__.py`` file is necessary for Python to 422 treat the directory as a package.) Then copy the file 423 ``myproject/settings/urls/main.py`` to ``myproject/apps/polls/urls/polls.py``. 424 425 Then, change ``myproject/settings/urls/main.py`` to remove the poll-specific 426 URLs and insert an ``include()``:: 427 428 <
