我正在尝试让管理站点为我的Django项目工作。我正在学习本教程https://docs.djangoproject.com/en/1.4/intro/tutorial02/,我正在使用Django 1.4。
Urls.py:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^$', include('polls.urls')),
# Examples:
# url(r'^$', 'Blog.views.home', name='home'),
# url(r'^Blog/', include('Blog.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
#url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
settings.py是:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'dev.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
#'django.contrib.admindocs',
)
我得到的错误信息是:
DoesNotExist at /admin/
Site matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.4
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
Exception Location: /Users/IMAC/work3/env/lib/python2.7/site-packages/django/db/models/query.py in get, line 366
Python Executable: /Users/IMAC/work3/env/bin/python
Python Version: 2.7.1
Python Path:
['/Users/IMAC/work3/Blog',
'/Users/IMAC/work3/env/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/Users/IMAC/work3/env/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
'/Users/IMAC/work3/env/lib/python27.zip',
'/Users/IMAC/work3/env/lib/python2.7',
'/Users/IMAC/work3/env/lib/python2.7/plat-darwin',
'/Users/IMAC/work3/env/lib/python2.7/plat-mac',
'/Users/IMAC/work3/env/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/IMAC/work3/env/Extras/lib/python',
'/Users/IMAC/work3/env/lib/python2.7/lib-tk',
'/Users/IMAC/work3/env/lib/python2.7/lib-old',
'/Users/IMAC/work3/env/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/IMAC/work3/env/lib/python2.7/site-packages']
不确定是什么问题?需要一些指导。非常感谢任何帮助。
答案 0 :(得分:2)
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'data.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'try',
)
urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
)
运行syncdb以创建数据库和用户。然后它应该工作。
答案 1 :(得分:2)
在本教程中我遇到了同样的问题。您在尝试创建超级用户时提到了Python错误,是下面的那个吗?
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 428, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8
这与终端的区域设置有关。有关SO解决方案,请参阅here。 运行那里提到的两个export命令,删除你的数据库文件,运行'python manage.py syncdb'再次创建数据库,输入'yes'来创建超级用户。这不应该再给你一个错误,你现在应该能够访问localhost上的管理站点。
答案 2 :(得分:1)
迟到的回复..
但我从这里得到了解决这个问题的方法
http://satishgandham.com/2012/04/error-whil-creating-super-user-in-django1-4-on-mac/
根据评论编辑
通过在添加用户
之前在终端中运行此命令来解决此问题export LANG="en_US.UTF-8"
我猜这个字符编码问题在运行syncdb时是访问django1.4的管理部分时出现以下错误的原因