我正在尝试遵循https://docs.djangoproject.com/en/dev/intro/tutorial01/上的 Django 教程
我创建了自己的模型,如下所示:
from django.db import models
class Order(models.Model):
name = models.CharField(max_length=30)
quantity = models.IntegerField()
我的 settings.py 看起来像:
ROOT_URLCONF = 'lcf.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'lcf.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
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',
'lcf',
)
并且 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('',
# Examples:
# url(r'^$', 'tsg.views.home', name='home'),
# url(r'^tsg/', include('tsg.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)),
)
但是,运行后
python manage.py syncdb
然后运行
python manage.py runserver
浏览器显示以下错误:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.4.1
Python Version: 2.6.6
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'lcf')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/home/staff/nallurv/Envs/tsg/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/home/staff/nallurv/Envs/tsg/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
298. for pattern in self.url_patterns:
File "/home/staff/nallurv/Envs/tsg/lib/python2.6/site-packages/django/core/urlresolvers.py" in url_patterns
328. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/staff/nallurv/Envs/tsg/lib/python2.6/site-packages/django/core/urlresolvers.py" in urlconf_module
323. self._urlconf_module = import_module(self.urlconf_name)
File "/home/staff/nallurv/Envs/tsg/lib/python2.6/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
Exception Type: ImportError at /
Exception Value: No module named urls