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.
In 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
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
:
from django.contrib import admin
from .models import MyModel
admin.site.register(MyModel)
Now it should appear when you visit /admin
.
Place this code inside your app's admin.py
file. Replace myapp
with your app name and Author
with your model name.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.