gpt4 book ai didi

python - Django 管理页面错误

转载 作者:太空宇宙 更新时间:2023-11-04 09:18:37 27 4
gpt4 key购买 nike

我正在创建一个 Django 应用程序。这样做我启用了 Django 管理站点,我可以看到它工作正常。然后我创建了一些模型并通过我的应用程序中的表单将数据插入其中。但是我无法通过 Django 的管理面板看到输入的值。我发现这是因为我没有在我的应用程序文件夹中包含 admin.py 文件。然后我创建了一个 admin.py 文件,运行 syndb 并尝试了。现在它抛出一个错误

ImportError at /admin/<br/>
No module named UniversityDetails.models

我将粘贴我的 admin.py、models.py 和项目文件夹结构。请帮我解决这个问题。

模型.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
申请名称:大学详情

回溯

    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

最佳答案

尝试

from universityDB.universityDetails.models import *
from django.contrib import admin

class UniversityDetailsAdmin(admin.ModelAdmin):
fields = ['firstName ', 'lastName ']
list_display = ('firstName ', 'lastName ')
search_fields = ['firstName ', 'lastName ']

admin.site.register(UniversityDetails,UniversityDetailsAdmin)

关于python - Django 管理页面错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5467927/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com