NameError: name 'admin' is not defined 解决问题的方法:

步骤:

1、修改settings.py。在INSTALLED_APPS设置中添加“django.contrib.admin”。

2、运行python manage.py syncdb更新数据库

3、修改urls.py。改为:

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

 

# Uncomment this for admin:
   (r'^admin/', include('django.contrib.admin.urls')),
   去掉注释。

在运行时,遇到这种问题:注意空格的问题

Traceback (most recent call last): File "D:\python2.6\lib\site-packages\django\core\servers\basehttp.py", line 279, in run self.result = application(self.environ, self.start_response) File "D:\python2.6\lib\site-packages\django\core\servers\basehttp.py", line 651, in __call__ return self.application(environ, start_response) File "D:\python2.6\lib\site-packages\django\core\handlers\wsgi.py", line 241, in __call__ response = self.get_response(request) File "D:\python2.6\lib\site-packages\django\core\handlers\base.py", line 73, in get_response response = middleware_method(request) File "D:\python2.6\lib\site-packages\django\middleware\common.py", line 56, in process_request if (not _is_valid_path(request.path_info) and File "D:\python2.6\lib\site-packages\django\middleware\common.py", line 142, in _is_valid_path urlresolvers.resolve(path) File "D:\python2.6\lib\site-packages\django\core\urlresolvers.py", line 294, in resolve return get_resolver(urlconf).resolve(path) File "D:\python2.6\lib\site-packages\django\core\urlresolvers.py", line 216, in resolve for pattern in self.url_patterns: File "D:\python2.6\lib\site-packages\django\core\urlresolvers.py", line 245, in _get_url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "D:\python2.6\lib\site-packages\django\core\urlresolvers.py", line 240, in _get_urlconf_module self._urlconf_module = import_module(self.urlconf_name) File "D:\python2.6\lib\site-packages\django\utils\importlib.py", line 35, in import_module __import__(name) File "D:\python2.6\Scripts\newtest\..\newtest\urls.py", line 17, in <module> (r'^admin/', include(admin.site.urls)), NameError: name 'admin' is not defined 解决问题的方法:
在urls.py中添加:from django.contrib import admin
二、增加超级用户
manage.py shell
>>>from django.contrib.auth.create_superuser import createsuperuser
>>>createsuperuser()
以上语句可能不能执行,可以改为执行:>>>python manage.py createsuperuser
 进入admin管理页面,想将英文显示中文化:
将settings.py中 LANGUAGE_CODE 由 'en-us' 改为 'zh-cn' , TIME_ZONE 建议改为 'CCT'
posted @ 2010-06-11 15:10  Phenix.  阅读(8968)  评论(2编辑  收藏  举报