I can't add new model to django's admin site. There is only one app can display its models and the other apps cannot add their models to admin site.
Here is my settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'Home',
'Scope',
'Trend',
'Log',
'Lab',
'Club',
'Article',
'Search',
'page_test',
Here is the urls.py:
from django.conf.urls import patterns, include, url
from cretus import views
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'cretus.views.home', name='home'),
# url(r'^cretus/', include('cretus.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
#url(r'^$', include('Home.urls')),
url(r'^$', include('page_test.urls')),
url(r'^page/', include('Home.urls')),
url(r'^search/', include('Search.urls')),
url(r'^test/', include('page_test.urls')),
#url(r'artistsearch/', include('Search.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^artscopes/', include('Scope.urls')),
url(r'^trend/', include('Trend.urls')),
url(r'^log/', include('Log.urls')),
url(r'^lab/', include('Lab.urls')),
url(r'^club/', include('Club.urls')),
url(r'^privacy/$', views.privacy, name='privacy'),
url(r'thanks/$', views.thanks, name='thanks'),
url(r'^contest/$', views.contestForm, name='contest'),
url(r'^terms/$', views.terms, name='terms'),
#url(r'^test/$', views.test, name='test'),
#url(r'^(?P<title>[a-zA-Z0-9_-]{0,100})/$', views.getArticleByTitle, name='test'),
#url(r'^article/', include('Article.urls')),
url(r'^article/', include('page_test.urls')),
# Apps
url(r'^tinymce/', include('tinymce.urls')),
url(r'^ckeditor/', include('ckeditor.urls')),
url(r'^sitemap.xml$', views.sitemap, name='sitemap'),
url(r'^googlesearch/$', views.googlesearch, name='googlesearch'),
url(r'^legal/$', views.legal, name='legal'),
url(r'^', views.error, name='error'),
)
Here is one of the admin.py:
from django.contrib import admin
from Lab.models import AttendeeInfo
class AttendeeInfoAdmin(admin.ModelAdmin):
list_display = ('fname', 'lname', 'email', 'video_url', 'package_name')
admin.site.register(AttendeeInfo, AttendeeInfoAdmin)
This problem has been solved. It is because the permission has not been granted to this user. So next time when you found you have done all of the procedures but still cannot find your model in the admin console, you may need to check this user's permission.
Related
I am trying to create a web app using Django framework. I followed the tutorial and did everything as per the tutorial.
DJANGO_PROJECT:
from django.contrib import admin
from django.urls import include
from django.conf.urls import url
urlpatterns = [
url(r'^dellserver/', include('dellserver.urls')),
url(r'^admin/', admin.site.urls),
]
Settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dellserver'
]
dellserver\urls.py:
from . import views
from django.conf.urls import url
urlpatterns = [
url(r'^dellserver/$', views.index, name="index")
]
views.py:
from django.http import HttpResponse
def index(request):
return HttpResponse("<h1>Hello World</h1>")
Can anybody tell me what I am doing wrong? Why I a getting the **
Page not found (404)
**
You did the mistake in project's url (folder which include settings.py file)
from django.contrib import admin
from django.urls import include
from django.conf.urls import url
urlpatterns = [
url(r'^/', include('dellserver.urls')), # this line you did the Mistake
url(r'^admin/', admin.site.urls),
]
in main urls remove dellserver as shown below.
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('dellserver.urls')),
]
so that you can call your url ../dellserver/, otherwise you have to call it ../dellserver/dellserver twice.
at first I successfully install django markdown
pip install django-markdown
than I add django-markdown in my setting.py file
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
'django-markdown',
]
then, I change my urls.py like as:
from django.conf.urls import include, url
from django.contrib import admin
from resume import views
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^home/$', views.home, name='home'),
url(r'^blog/', include('blog.urls',namespace='blog',app_name='blog')),
url('^markdown/', include('django_markdown.urls')),
]
I also change my admin.py file like as:
from django.contrib import admin
from .models import Post
from django_markdown.admin import MarkdownModelAdmin
class PostAdmin(admin.ModelAdmin):
list_display = ('title','slug','author','publish','status')
list_filter = ('status','created','publish','author')
search_fields = ('title','body')
prepopulated_fields = {'slug':('title',)}
raw_id_fields = ('author',)
date_hierarchy = 'publish'
ordering = ['status','publish']
# Register your models here.
admin.site.register(Post,MarkdownModelAdmin, PostAdmin)
but, when I start my runserver, django gives me an error like this:
ModuleNotFoundError: No module named 'django-markdown'
how can i solve my problem?
In installed apps you should add django_markdown instead of django-markdown
I am getting the following error.
Reverse for 'facebook_channel' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
The following line is red.
{% providers_media_js %}
These are my settings from local_settings.py
SOCIALACCOUNT_PROVIDERS = \
{'facebook':
{'SCOPE': ['email', 'publish_stream'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'METHOD': 'js_sdk',
'LOCALE_FUNC': lambda request: 'en_GB',
'VERIFIED_EMAIL': False}}
SOCIALACCOUNT_QUERY_EMAIL = True
settings.py
SITE_ID = 1
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.request',
# allauth specific context processors
'allauth.account.context_processors.account',
'allauth.socialaccount.context_processors.socialaccount',
)
THIRD_PARTY_APPS = (
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'suit',
'debug_toolbar',
'south',
'crispy_forms',
'haystack',
'taggit',
'bootstrapform',
'sorl.thumbnail',
)
Yes, I have done the model migrations, I have the four tables that allauth creates.
Any help will be much appreciated, it's been bugging me for a while.
Updated
Main urls.py
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('useraccount.urls')),
url(r'^directory/', include('directory.urls')),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()
urlpatterns += url(r'', 'directory.views.home', name='home'),
if settings.DEBUG:
import debug_toolbar
urlpatterns += patterns('',
url(r'^__debug__/', include(debug_toolbar.urls)),
)
Updated
urls.py inside useraccount app
from django.conf.urls import patterns, url, include
from django.contrib.auth.decorators import login_required, permission_required
from useraccount.views import AccountView, ProfileUpdateView, ProfileDetailView
urlpatterns = patterns('',
(r'^logout', 'django.contrib.auth.views.logout', {'next_page': 'directory_home'}),
url(r'^profile/(?P<pk>\w+)', ProfileDetailView.as_view(), name='useraccount_profile'),
url(r'^edit', login_required(ProfileUpdateView.as_view()), name='useraccount_edit'),
url(r'^dashboard', login_required(AccountView.as_view()), name='useraccount_dashboard'),
url(r'', include('allauth.account.urls')),
)
You'll need to include the correct allauth urls in your url conf
url(r'', include('allauth.urls'))
I am using django-registration app with custom templates, and the django admin. For some reason, the admin template "password_change_form" is being replaced by the custom template from the registration app. I have no idea what I'm doing wrong here. I want the admin to use its own original templates. I'm using Django 1.5. Any help is GREATLY appreciated.
Here is what I have for urlpatterns:
urlpatterns = patterns('',
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('registration.backends.default.urls')),
(r'^accounts/profile', views.profile ),
)
And my TEMPLATE_DIRS and INSTALLED_APPS:
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
TEMPLATE_DIRS = (
os.path.join(PROJECT_ROOT, 'templates/'),
os.path.join(PROJECT_ROOT, '../registration/templates/'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'registration',
)
Is there something I am missing??
Ok so finally figured it out. Turns out the django-registration app templates were conflicting with the admin registration templates. To fix this, I changed the folder name where my custom django-registration templates are from "registration" to "myreg" (since the admin registration templates are also under a folder called "registration", which is what I believe was confusing django). Then in the auth_urls.py file of the django-registration app, I changed the template name from "registration/..." to "myreg/..." and added the template name argument to all patterns that don't have it. So auth_urls.py would be like this:
urlpatterns = patterns('',
url(r'^login/$',
auth_views.login,
{'template_name': 'myreg/login.html'},
name='auth_login'),
url(r'^logout/$',
auth_views.logout,
{'template_name': 'myreg/logout.html'},
name='auth_logout'),
url(r'^password/change/$',
auth_views.password_change,
{'template_name': 'myreg/password_change_form.html'},
name='auth_password_change'),
url(r'^password/change/done/$',
auth_views.password_change_done,
{'template_name': 'myreg/password_change_done.html'},
name='auth_password_change_done'),
url(r'^password/reset/$',
auth_views.password_reset,
{'template_name': 'myreg/password_reset_form.html'},
name='auth_password_reset'),
url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
auth_views.password_reset_confirm,
{'template_name': 'myreg/password_reset_confirm.html'},
name='auth_password_reset_confirm'),
url(r'^password/reset/complete/$',
auth_views.password_reset_complete,
{'template_name': 'myreg/password_reset_complete.html'},
name='auth_password_reset_complete'),
url(r'^password/reset/done/$',
auth_views.password_reset_done,
{'template_name': 'myreg/password_reset_done.html'},
name='auth_password_reset_done'),
)
This should solve the issue and allow Django to use separate templates for admin and django-registration.
A trick how to easily check the order in which template folders are processed.
modify your urls.py to:
from django.views.generic import TemplateView
...
urlpatterns = patterns('',
...
url(r'test/', TemplateView.as_view(template_name="i-dont-exist.html")),
...
)
Ensure your settings.DEBUG and TEMPLATE_DEBUG are set to True and load the '/test/' url in your browser.
This should return a ErrorPage with a TemplateDoesNotExist Exception.
Scroll down to the Template-loader postmortem this shows you the order in which your template folders are checked for files.
I have uncommented the admin areas in settings.py & urls.py. However the admin won't load at /admin/. If I change the url to /admin/auth/ then I can login the admin panel, but if I try and go to /admin/ it still won't find the page.
Here is my settings.py :
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'src',
'lib.tagging',
'lib.markdown',
'lib.avatar',
# Uncomment the next line to enable admin documentation:
#'django.contrib.admindocs',
)
URLs.py
from django.conf.urls.defaults import *
from django.conf import settings
from src import views
from src.models import Want
from lib.tagging.models import Tag
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
want_info_dict = {
'queryset': Want.objects.all(),
'date_field': 'pub_date',
}
urlpatterns = patterns('django.views.generic.simple',
url(r'^about/$', 'direct_to_template', {"template":"about.html"}, name="about"),
)
urlpatterns += patterns('',
url(r'^$', views.home, name="home"),
url(r'^signup/$', views.signup, name="signup"),
url(r'^accounts/login/$', views.userlogin, name="login"),
url(r'^accounts/settings/$', views.account_settings, name="settings"),
url(r'^logout/$', 'django.contrib.auth.views.logout', {"next_page":"/"}, name="logout"),
#user profile
url(r'^(?P<username>\w+)/$', views.userprofile, name="user-profile"),
#wants
url(r'^mentees/(?P<slug>[-\w]+)/$', views.wants_by_tag, name="wants_by_tag"),
url(r'^avatar/', include('lib.avatar.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
)
Thanks for the help!
the urlpattern for user-profile conflicts with admin, what happens when you move that pattern to the end, or better yet, prefix it like r'^users/(?P<username>\w+)/$'