python 应用程序不会显示在 Django 管理中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2002549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 23:31:59  来源:igfitidea点击:

Apps won't show in Django admin

pythondjangodjango-adminpinax

提问by philgo20

I've read all the other threads but I still don't get why my apps are not showing up in Django admin. Everything else works fine.

我已经阅读了所有其他线程,但我仍然不明白为什么我的应用程序没有出现在 Django 管理中。其他一切正常。

My apps are in settings.py

我的应用程序在 settings.py 中

I have admin.autodiscover in my root urls.py file

我的根 urls.py 文件中有 admin.autodiscover

from django.conf.urls.defaults import *
from django.conf import settings

from django.views.generic.simple import direct_to_template

from django.contrib import admin

admin.autodiscover()



urlpatterns = patterns('',
url(r'^$', direct_to_template, {
    "template": "homepage.html",
}, name="home"),

url(r'^admin/invite_user/$', 'signup_codes.views.admin_invite_user', name="admin_invite_user"),
url(r'^account/signup/$', "signup_codes.views.signup", name="acct_signup"),

(r'^account/', include('account.urls')),
(r'^profiles/', include('basic_profiles.urls')),
(r'^notices/', include('notification.urls')),
(r'^announcements/', include('announcements.urls')),
(r'^tagging_utils/', include('tagging_utils.urls')),
(r'^attachments/', include('attachments.urls')),
(r'^comments/', include('threadedcomments.urls')),
#
(r'^wayfinder/', include('wayfinder.urls')),
(r'^site/', include('jsite.urls')),
(r'^kiosk/', include('kiosk.urls')),
(r'^navigator/', include('navigator.urls')),
(r'^location/', include('location.urls')),
(r'^event/', include('event.urls')),
#(r'^news_reader/', include('news_reader.urls')),
#(r'^weather_reader/', include('weather_reader.urls')),

(r'^admin/(.*)', admin.site.root),
)

if settings.SERVE_MEDIA:
urlpatterns += patterns('',
    (r'^site_media/', include('staticfiles.urls')),
)

All my apps have an admin.py file containing something like

我所有的应用程序都有一个包含类似内容的 admin.py 文件

from django.contrib import admin
from event.models import Event

class EventAdmin(admin.ModelAdmin):
    list_display = (
                'short_name',
                'long_name',
                'locations',
                'categories',
                'description',
                'phone',
                'email',
                'url_source',
                'url_location',
                'external_ref',
                'show_event'
            )

admin.site.register(Event, EventAdmin)

And I have restarted the server over and over ;-)

我一遍又一遍地重新启动服务器;-)

I am building on top of Pinax, but from my reading, it shouldn't change anything. Any clue what might be wrong ?

我建立在 Pinax 之上,但从我的阅读来看,它不应该改变任何东西。任何线索可能是错误的?

回答by JAL

Do you have your apps in the INSTALLED_APPS section in settings.py? Make sure it has your apps listed there. My section reads

你的应用程序在 settings.py 的 INSTALLED_APPS 部分吗?确保其中列出了您的应用程序。我的部分阅读

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.sites',
'squick.items',
'cowsite.search',
'cowsite.posts',

)

)

for instance. I'm pretty sure for security, they won't show up in the admin unless they are in installed apps. I think I had this same issue, where I couldn't get cowsite to show up in the admin.

例如。我很确定安全性,除非它们在已安装的应用程序中,否则它们不会出现在管理员中。我想我遇到了同样的问题,我无法让 cowsite 出现在管理员中。

The Django docssay about the admin page: "By default, it displays all the apps in INSTALLED_APPS that have been registered with the admin application, in alphabetical order"

Django 文档对管理页面说:“默认情况下,它会按字母顺序显示 INSTALLED_APPS 中所有已在管理应用程序中注册的应用程序”

回答by Antony Hatchkins

Are you logging in to admin as a superuser? If not, it could be a permissions problem.

您是否以超级用户身份登录 admin?如果没有,则可能是权限问题。

回答by Ivan

By coincidence I had the same problem this morning. Briefly, this is what worked for me (see references for details):

巧合的是,我今天早上遇到了同样的问题。简而言之,这对我有用(有关详细信息,请参阅参考资料):

In the top level directory of MyApp (ie same directory as models.py, etc.) I added a python module admin.py, containing:

在MyApp的顶层目录(即models.py等同目录)添加了一个python模块admin.py,包含:

from models import ThisModel, ThatModel
from django.contrib import admin

admin.site.register(ThisModel)
admin.site.register(ThatModel)

Then in mysite directory I did syncdb and runserver, and ThisModel and ThatModel were in the admin interface.

然后在 mysite 目录中,我做了 syncdb 和 runserver,而ThisModel 和 ThatModel 在管理界面中。

Does that work for you?

那对你有用吗?

Best wishes

最好的祝愿

Ivan

伊万

** References

** 参考

(I am a new member so I am allowed to post one hyperlink only!)

(我是新会员所以只能发一个超链接!)

Django tutorial: Make the poll app modifiable in the admin

Django 教程:使投票应用程序在管理员中可修改

There was also a query on the Pinax google group recently titled, "How to add my app to Admin in a Pinax project?"

最近在 Pinax google group 上也有一个问题,标题是“如何在 Pinax 项目中将我的应用添加到管理员?”

回答by Ron E

For other's coming across this, I had the same issue due to grappelli.dashboard being in the installed apps but not actually installed in the virtualenv, so do a pip freeze and ensure all your requirements are actually installed.

对于其他人遇到的这个问题,我遇到了同样的问题,因为 grappelli.dashboard 在已安装的应用程序中,但实际上并未安装在 virtualenv 中,因此请执行 pip freeze 并确保实际安装了所有要求。

回答by Christian V Johansen

I had the same problem, what worked for me was changing this line in urls.py:

我遇到了同样的问题,对我有用的是在 urls.py 中更改这一行:

url(r'^admin/', include(admin.site.urls)),

to

url('^admin/', include(admin.site.urls)),

(Removing the rin the first bit of code) For some reason I am not aware of, the Polls became visible in admin after that.

(删除代码的第一位中的r)出于某种我不知道的原因,此后民意调查在管理员中可见。

回答by hasib

add your app name in "settings.py" file installed app.

在已安装应用程序的“settings.py”文件中添加您的应用程序名称。

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myapp',


]

回答by czarchaic

Not sure which version of django you're using but the current docs suggest includingthe admin urls.

不确定您使用的是哪个版本的 django,但当前的文档建议包括管理 url。

 ('^admin/', include(admin.site.urls))

回答by Daniel Roseman

You didn't answer Antony's question. Are you logging in as a superuser, or at least with a user with add/edit rights for the applications? If not, you won't see them.

你没有回答安东尼的问题。您是以超级用户身份登录,还是至少以对应用程序具有添加/编辑权限的用户身份登录?如果没有,您将看不到它们。