我正在創建一個Django應用程序。這樣做我啓用了Django管理站點,我可以看到它工作正常。然後我創建了一些模型,並通過我的應用程序中的表單插入數據。但是我無法通過Django的管理面板看到輸入的值。我發現它是因爲我沒有在應用程序文件夾中包含一個admin.py文件。然後我創建了一個admin.py文件,運行syndb並嘗試。現在,它拋出一個錯誤Django管理頁面錯誤
ImportError at /admin/
No module named UniversityDetails.models
我會貼上我的admin.py,models.py和項目文件夾結構。請幫我解決這個問題。
Models.py
from django.db import models
class UniversityDetails(models.Model):
firstName = models.CharField(max_length=200)
lastName = models.CharField(max_length=200)
email = models.EmailField()
password = models.TextField()
birthday = models.TextField()
sex = models.CharField(max_length=10)
admin.py
from universityDetails.models import *
from django.contrib import admin
admin.site.register(UniversityDetails)
項目名稱:universityDB
應用名稱:universityDetails
TRACEBACK
Environment:
Request Method: GET
Request URL: http://10.1.0.90:8080/admin/
Django Version: 1.2.5
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'universityDetails',
'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
91. request.path_info)
File "/usr/local/lib/python2.6/dist-packages/django/core/urlresolvers.py" in resolve
215. for pattern in self.url_patterns:
File "/usr/local/lib/python2.6/dist-packages/django/core/urlresolvers.py" in _get_url_patterns
244. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.6/dist-packages/django/core/urlresolvers.py" in _get_urlconf_module
239. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/rv/Desktop/universityDB/../universityDB/urls.py" in <module>
5. admin.autodiscover()
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/__init__.py" in autodiscover
24. import_module('%s.admin' % app)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/rv/Desktop/universityDB/universityDetails/admin.py" in <module>
1. from UniversityDetails.models import *
Exception Type: ImportError at /admin/
Exception Value: No module named UniversityDetails.models
我以爲你說你改變了第1行到我的版本?當您將導入行更改爲'from universityDB.universityDetails.models import *'時,回溯是什麼? – 2011-03-29 05:15:09
這是你告訴我的修改的追溯。 – 2011-03-29 05:24:35
這個回溯表示'universityDetails/admin.py'的第1行是'from UniversityDetails.models import *' - 你重啓服務器嗎? – 2011-03-29 05:27:50