我的项目名称为practice
,我的应用程序名称为testapp
。这是我的项目结构:
django/bin/practice
\practice
-practice folder
-__init__.py
-settings.py
-urls.py
-wsgi.py
-testapp folder
-migrations folder
-templates folder
-index.html
-__init__.py
-admin.py
-models.py
-tests.py
-views.py
-manage.py
我已将INSTALLED_APPS
中的应用名称包含在settings.py
中,但我仍然收到此错误:
ImportError: no module named testapp in django
<pre>Environment:
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.8.5
Python Version: 2.7.8
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'testapp')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
119. resolver_match = resolver.resolve(request.path_info)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve
365. for pattern in self.url_patterns:
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in url_patterns
401. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in urlconf_module
395. self._urlconf_module = import_module(self.urlconf_name)
File "C:\Python27\lib\importlib\__init__.py" in import_module
37. __import__(name)
File "C:\Python27\Lib\site-packages\django\bin\practice\practice\urls.py" in <module>
22. url(r'^practice/', include(testapp.views.home))
Exception Type: NameError at /
Exception Value: name 'testapp' is not defined</pre>