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+)/$'
Related
Hi, I have Blog post project some functionalities made with DRF and some functionalities made with Django.I need to add 404 page for missing urls. But If I use right-working link, I will get server error, However, I will get 404 page for missing url.
For example, urls such as '127.0.0.1:8000/en/me' or '127.0.0.1:8000/en/me/contact/' or '127.0.0.1:8000/en/book' will bring server error,
but url '127.0.0.1:8000/en/men' return not found page
in my django_project/urls.py:
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from django.conf.urls.i18n import i18n_patterns
# from django.conf.urls import handler404
from my_works import views as my_works_views
schema_view = get_schema_view(
openapi.Info(
title="API Docs",
default_version='v1',
description="API urls description",
terms_of_service="https://www.myblogs.com/policies/terms/",
contact=openapi.Contact(email="aahmadov271101#gmail.com"),
license=openapi.License(name="Test License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)
urlpatterns = [
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('i18n/', include('django.conf.urls.i18n')),
]
urlpatterns += i18n_patterns (
path('', include('my_works.urls')),
path('me/', include('accounts.urls')),
path('admin/', admin.site.urls),
)
urlpatterns+= (static(settings.STATIC_URL, document_root=settings.STATIC_ROOT))
urlpatterns+= (static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT))
handler404 = 'accounts.views.error_404_view'
admin.site.site_header = 'Alimardon Mustafoqulov Administration'
admin.site.site_title = 'Administration'
admin.site.index_title = 'Administration page'
in my django_app/urls.py:
from django.urls import path, include
from django.conf.urls.i18n import i18n_patterns
from .views import (
ArticlesViewList,
BooksViewList,
PresentationsViewList,
ProjectsViewList,
EventsViewList,
VideosViewList,
)
from rest_framework import routers
from django.conf.urls import handler404
router = routers.DefaultRouter()
router.register(r'articles', ArticlesViewList, basename='articles')
router.register(r'books', BooksViewList, basename='books')
router.register(r'presentations', PresentationsViewList, basename='presentations')
router.register(r'projects', ProjectsViewList, basename='projects')
router.register(r'events', EventsViewList, basename='events')
router.register(r'videos', VideosViewList, basename='videos')
urlpatterns = []
urlpatterns += router.urls
in my django_app2/urls.py:
from django.urls import path, include
from .views import ContactAPIView, ProfileView, AdminContactView, AddressLinkView
from rest_framework import routers
from django.contrib.auth import views as auth_views
from rest_framework.authtoken.views import obtain_auth_token
router = routers.DefaultRouter()
router.register(r'phones',AdminContactView, basename='phone')
router.register(r'addresses',AddressLinkView, basename='addresses')
router.register(r'contact',ContactAPIView, basename='contact')
router.register(r'',ProfileView, basename='profile')
urlpatterns = [
# path('auth-token/', obtain_auth_token, name='token-auth'),
path('api-auth/', include('rest_framework.urls')),
path('password-reset/',
auth_views.PasswordResetView.as_view(),
name='password_reset'),
path('password-reset/done/',
auth_views.PasswordResetDoneView.as_view(
template_name='password_reset_done.html'
),
name='password_reset_done'),
path('password-reset-confirm/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(),
name='password_reset_confirm'),
path('password-reset-complete/',
auth_views.PasswordResetCompleteView.as_view(),
name='password_reset_complete'),
]
urlpatterns += router.urls
in my django_project/settings.py:
import os
from pathlib import Path
from django.utils.translation import gettext_lazy as _ #for multi-language
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secret key hidden'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ["*",]
# Application definition
INSTALLED_APPS = [
'modeltranslation',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts.apps.AccountsConfig',
'my_works.apps.MyWorksConfig',
'crispy_forms',
'rest_framework',
'django_filters',
'rest_framework.authtoken',
'corsheaders',
'phonenumber_field',
'drf_yasg',
'whitenoise',
]
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.
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 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.
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.