Starting development server at http://127.0.0.1:8000/
Not Found: /admin/
[30/May/2021 20:33:56] "GET /admin/ HTTP/1.1" 404 2097
project/urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('marketability.mkbl_urls')),
path('admin/', admin.site.urls),
path(r'^ckeditor/', include('ckeditor_uploader.urls')),
]
variants path(r'admin/', admin.site.urls), and path(r'^admin/', admin.site.urls), don't works too.
project/marketability/mkbl_urls.py
from django.urls import path
from django.views.generic.base import RedirectView, TemplateView
from . import views
app_name = 'marketability'
handler404 = 'marketability.views.handler404'
urlpatterns = [
path('', views.home, name="home"),
path('<slug:cat_>/', views.page_Category_Main, name='cat'),
path('<slug:cat_>/<slug:product_>', views.page_Product, name='product'),
path('al_about.html', views.about, name="about"),
path('al_home.html', views.home, name="home"),
path('search_all.html', views.search_all, name="doorway"),
path('robots.txt', TemplateView.as_view(template_name="robots.txt", content_type="text/plain")),
path('sitemap.xml', TemplateView.as_view(template_name="sitemap.xml", content_type="text/xml")),
path('favicon.ico', RedirectView.as_view(url='/static/marketability/favicon.ico', permanent=True)),
]
project/marketability/admin.py
from django.contrib import admin
from .models import TxtHow, TxtRatings
# Register your models here.
admin.site.register(TxtHow)
admin.site.register(TxtRatings)
project/settings.py
....
NSTALLED_APPS = [
'ckeditor',
'ckeditor_uploader',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'marketability',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR + '/marketability/patterns'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
....
superuser has created
So, i don't see any deviations from Django Documentation.
How to solve it?
thks
Your path:
path('<slug:cat_>/', views.page_Category_Main, name='cat'),
will match with admin/ and thus see admin as the value for the cat_ slug, and thus trigger that view. Likely the view for that path will try to fetch an element with admin as slug, and fail to do this, and thus raise a HTTP 404 response.
You can put the urls for the admin/ and ckeditor/ before the one with your categories:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('ckeditor/', include('ckeditor_uploader.urls')),
path('', include('marketability.mkbl_urls')),
]
Django will visit the url patterns top to bottom, and thus trigger the first path pattern that matches, in that case the one with the admin.
It might however be better to prefix your marketability urls as well, for example with:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('ckeditor/', include('ckeditor_uploader.urls')),
path('market/', include('marketability.mkbl_urls')),
]
otherwise it is thus impossible to have a category named admin.
Related
I'm a beginner with Django and have been working a small project that requires quite a bit of styling. However, for some reason, Django isn't picking up on my static css file.
settings.py
from pathlib import Path
TEMPLATES_DIR = Path(BASE_DIR) / 'templates'
STATIC_DIR = Path(BASE_DIR) / 'static'
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'CalculatorApp'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'Calculator.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATES_DIR,],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'Calculator.wsgi.application'
...
STATIC_ROOT = Path(BASE_DIR) / 'static'
STATIC_URL = 'static/'
STATICFILE_DIRS = [
STATIC_DIR,
]
I double checked my spelling, settings.py directory, checked countless posts and can't seem to find a solution. This is my first time using stack overflow, so I'm assuming I just upload pictures of my code.
Edit: here are is my views.py and urls.py.
# Urls.py
from django.contrib import admin
from django.urls import path
from CalculatorApp import views
urlpatterns = [
path('', views.index, name='index'),
path('admin/', admin.site.urls),
]
# Views.py
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request, 'index.html')
I'm a beginner trying django for the first time trying to map my urls together, but after following the necessary steps the django installation page keeps on showing on my browser.
for my project app
from django import path
from django.urls import path
from . import views
urlpatterns = [
path('',views.index )
]
for my parent app
from xml.etree.ElementInclude import include
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.urls')),
]
for my project views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('good sir')
settings.py file is below
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'myproject.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
It looks like you are isung the incorrect include for your parent app urls.
Instead of importing from xml.etree.ElementInclude import from django.urls
Also remove from django import path the path you need to use for the urlpatterns is the one from django.urls
I'm not able to import my views in the app folder to the URLS of project folder. I've tried every possible methods like 'from . import views' or 'from newapp import views as newapp_views' and 2-3 more alternatives that I searched on the internet. My app name is newapp and project name is newproject. Please help me.
This is my models file:
from django.db import models
class User(models.Model):
first_name=models.CharField(max_length=128)
last_name=models.CharField(max_length=128)
email=models.EmailField(max_length=256, unique=True)
This is my URLS of newapp folder:
from django.conf.urls import url
from django.urls.resolvers import URLPattern
from .models import views
urlpatterns= [url(r'^$', views.users, name='users'),
]
This is my views of newapp folder:
from django.shortcuts import render
from .models import User
def index(request):
return render(request, 'newapp/index.html')
def users(request):
user_list=User.objects.order_by('first_name')
user_dict={'users': user_list}
return render(request, 'newapp/users.html', context=user_dict)
This is my URLS of newproect folder:
from django.contrib import admin
from django.urls import path,include
from newapp import views
urlpatterns = [
path('', views.index, name='index'),
path('users/',views.users, name="users"),
path('admin/', admin.site.urls),
]
This is my settings file:
from pathlib import Path
import os
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'newapp'
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
You can't import your file like this: from newapp import views.
And from . import views will work only if your urls.py file is in your app folder, while Django by default put it inside your project folder.
If you choose to have separated urls.py files per app (which is a good practice, as your project could grow into many apps), you could do the following:
newapp/urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('users/',views.users, name="users"),
path('admin/', admin.site.urls)
]
newproject/urls.py
from django.urls import path, include
urlpatterns = [
path('', include('newapp.urls'))
]
This way you just include the app urls in the project url file, and you can use a path to prefix all the app urls (instead of a blank string as above).
I have completed all seven steps of the Writing your first Django app tutorial for 3.0. Everything works great, except the base site URL for 'mysite' at http://127.0.0.1:8000/. At the beginning of the tutorial, it worked, but it stopped working as I progressed/at the end. http://127.0.0.1:8000/admin/ works fine. Can anyone tell me what I'm doing wrong?
Based on how the tutorial is structured, i.e. "add this and that and this and that," etc., that I overwrote something.
Here is the error I'm receiving in my browser:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
polls/
admin/
The empty path didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Here is the error I'm receiving in Terminal:
Not Found: /
[20/Jun/2020 11:01:22] "GET / HTTP/1.1" 404 2027
Here is my polls/urls.py file:
from django.urls import path
from . import views
app_name = 'polls'
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
path('<int:question_id>/vote/', views.vote, name='vote'),
]
Here is my mysite/urls.py file:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
Here is TEMPLATES in mysite/settings.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
SOLVED/ANSWER added from comments:
Answer from expert Willem Van Onsem
1. Edit mysite/urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('polls.urls')), # no /polls/ prefix
path('admin/', admin.site.urls),
]
2. Run python manage.py runserver
Can anyone tell me what I'm doing wrong?
All your paths for the poll app are here prefixed by polls/, since you wrote:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
You thus can visit the IndexView by fetching the http://127.0.0.1:8000/polls/ URI. If you do not want to prefix the urls, you can rewrite the root urls.py to:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('polls.urls')), # no /polls/ prefix
path('admin/', admin.site.urls),
]
Then you can simply visit http://127.0.0.1:8000/.
I'm setting production environment on EC2. The exactly same code is running on Dev and Prod, but gunicorn (prod) and different settings.py.
It's all working fine, but when a visitor tries to reset password he access the page "password_reset", fill the form with his email but, after submitting, get a 500 error.
When this occour, i'm emailed (admin emails) with this error saying:
"Internal Server Error: /accounts/password_reset/
NoReverseMatch at /accounts/password_reset/
Reverse for 'auth_password_reset_confirm' not found. 'auth_password_reset_confirm' is not a valid view function or pattern name."
What i understand is that "/accounts/password_reset/" is trying to call an "auth_password_reset_confirm" that indeed does not exist (the correct url name is "password_reset_confirm"). But i don't know who is adding this "auth_" before.
I've tried:
1) Confirm on dev and prod that the url name given from django.contrig.auth is "password_reset_confirm"
2) Downloaded server version of django.contrib.auth and confirm no "auth_" is being added to the call.
3) Confirm that i didn't add "auth_" on any url name on my apps.
common_settings.py:
INSTALLED_APPS = [
#My Apps
'institutional', #External generic public pages
'lab', #Internal pages and controllers
'shop', #External shop pages and controllers
'account', #Group of dynamics to handle users, members (profile)
'django.contrib.auth', #Here just because of django_registration password reset issues if this line was after
#Third-party Apps
'django_registration',
'snowpenguin.django.recaptcha3',
'pagseguro',
'polymorphic',
'django_countries',
'compressor',
#Django Default Apps
'django.contrib.sitemaps',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'myapp.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'myapp.wsgi.application'
# Password validation
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Django auth configuration
LOGIN_URL = '/accounts/login/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
myapp.urls.py:
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.contrib.staticfiles.urls import static, staticfiles_urlpatterns
urlpatterns = [
#Default admin app urls
path('admin/', admin.site.urls),
#Account pages
path('accounts/', include('account.urls')),
#Pattern to allow lazy translations
path('i18n/', include('django.conf.urls.i18n')),
]
#Media and images configuration
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
accounts.urls.py:
from django.urls import path, include
from . import views, forms, regbackend
from django_registration.backends.activation.views import RegistrationView
urlpatterns = [
#Account necessary views
path('register/', RegistrationView.as_view(form_class=forms.ExtendedRegistrationForm), name='django_registration_register'),
path('member/', views.member_read, name='accounts.member_read'),
path('member/update', views.member_update, name='accounts.member_update'),
#Account pages from Django Auth and django_registration
path('login/', views.ExtendedLoginView.as_view(), name='login'),
path('', include('django.contrib.auth.urls')),
path('', include('django_registration.backends.activation.urls')),
]
I realy dont understand what is going on, can anyone help me?
I did a turn around here adding this url to my accounts.url.py:
from django.contrib.auth.views import PasswordResetConfirmView
...
path('reset/<uidb64>/<token>/', PasswordResetConfirmView.as_view(), name='auth_password_reset_confirm'),
And it's working. But i really need to understand who's calling this page.
Thanks