[英]app not showing in django admin site
i am trying to add app in django admin site, but the app is not showing, i have searched other questions for answer but they are almost 7 years old and it's all becoming very confusing, can someone help me please. 我正在尝试在django管理站点中添加应用程序,但是该应用程序未显示,我已经搜索了其他问题以寻求答案,但是它们已经快7年了,而且变得非常混乱,有人可以帮我吗。
In settings.py: 在settings.py中:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',
]
Following is the code in project's urls.py 以下是项目的urls.py中的代码
from django.conf.urls import url
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
url(r'^admin/', admin.site.urls),
]
Make sure you add 确保您添加
from django.contrib import admin
from mymodel.models import mymodel
admin.site.register(mymodel)
To 至
myapp/admin.py
You should register your myapp
's models in myapp/admin.py
: 您应该在
myapp/admin.py
注册myapp
的模型:
from django.contrib import admin
from .models import MyModel
admin.site.register(MyModel)
Now it should appear when you visit /admin
. 现在,它应该在您访问
/admin
时出现。
Place this code inside your app's admin.py
file. 将此代码放在您应用的
admin.py
文件中。 Replace myapp
with your app name and Author
with your model name. 将
myapp
替换为您的应用程序名称,将Author
替换为您的型号名称。
from django.contrib import admin
from myapp.models import Author
admin.site.register(Author)
It is documented at https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#modeladmin-objects 它记录在https://docs.djangoproject.com/zh/1.11/ref/contrib/admin/#modeladmin-objects
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.