The Django admin page is not opening. Where am I going wrong? - python

I've just started working with Django 3.0.1. I used the python manage.py runserver command and tried opening localhost:8000/admin page but I get hit with a "GET / HTTP/1.1" 200 3731 in the command prompt and the server stops running.
This is the urls configuration for the basic page I have been working on.
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls), #navigation url for admin page
path('', include('blog.urls')),
]
Is there any error which I have to rectify?

Related

404 error when looking for page on Django site

I'm trying to create a media page on my site through Django. I'm following a course and I'm pretty stumped. I'm following exactly what the guy is doing but I keep getting the following error:
Error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in portfolio.urls, Django tried these URL patterns, in this order:
admin/
^media/(?P<path>.*)$
My settings.py:
MEDIA_ROOT = BASE_DIR/'media'
MEDIA_URL = '/media/'
urls.py:
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
The problem arises as soon as I enter this line:
+ static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
I haven't written anything in the views.py folders yet because the course hasn't required me to on this project so far.
I'm just a newbie so I don't really have any clue what's happening when the code looks correct but I'm still running into the issue.
Any help is appreciated.
As the error message says, your site has these 2 address available for access.
admin/
^media/(?P<path>.*)$
However, you are requesting for http://127.0.0.1:8000/ instead.
Maybe try http://127.0.0.1:8000/media/image.jpg for exmaple.

Django - The current path, job/all, matched the last one. - But it still returns 404

When I go to this URL http://127.0.0.1:8000/job/all I am always receiving a 404 error with this message:
404 Django Error screenshot
However, when I just go to http://127.0.0.1:8000/ or http://127.0.0.1:8000 it always finds the / (index) route correctly regardless if there is a trailing slash, or not. This issue seems to only happen with the /job/WHATEVER_ELSE_GOES_HERE URLs.
I have the following URLs setup:
My jobs app urls.py:
from django.urls import path
from .views import *
urlpatterns = [
path('', index, name="index"),
path('job/<int:job_id>', job_details, name="job_detail"),
path('job/all/', all_jobs, name="all_jobs"),
path('job/add/', add_job, name="add_job"),
path('job/my_posted_jobs/', my_posted_jobs, name="my_posted_jobs"),
path('job/delete/<int:job_id>', delete_job, name="delete_job"),
path('job/search', search_job, name="search_job"),
path('job/apply_for_job/<int:job_id>', apply_for_job, name="apply_for_job")
]
My project's urls.py:
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('jobs.urls')),
path('user/', include('users.urls')),
path('payments/', include('payments.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
In the error message (screenshot) it also says this:
The current path, job/all, matched the last one.
How come it matches a URL but returns 404?
How do I fix it?
Thank you
You have to include the "/" since you have included it in your syntax in your urls.py therefore call the url from your web browser using the link below when you have started the Django web server.
http://127.0.0.1:8000/job/all/

page not found : / Django

I'm new to Django and I want to add new url but I got this error:
Watching for file changes with StatReloader
System check identified no issues (0 silenced).
July 14, 2020 - 20:19:51
Django version 2.2.2, using settings 'cineam.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Not Found: /
here is my url.py:
from django.contrib import admin
from django.urls import path, include
from ticketing import urls
urlpatterns = [
path('admin/', admin.site.urls),
path('ticketing/', include(urls))
]
ticketing/urls.py :
from django.urls import path
from ticketing.views import cinema_list
urlpatterns=[
path('movies/list/', cinema_list),
]
can anybody help me?
You haven't mentioned which URL you were trying to access.I assume you were trying to access localhost:8000 or http://127.0.0.1:8000/. in this case you will get this error "Page NOT FOUND."
Try this and then try accessing the same URL again, It will work
from django.contrib import admin
from django.urls import path, include
from ticketing import urls
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("ticketing.urls"))
]
else if you were accessing localhost:8000/ticketing/ it will still bring the error because
you have not pointed which urls.py file you are trying to access. In that case...
from django.contrib import admin
from django.urls import path, include
from ticketing import urls
urlpatterns = [
path('admin/', admin.site.urls),
path('ticketing/', include("ticketing.urls"))
]

How to fix "Page not found (404)" error ("Django tried these URL patterns... The empty path didn't match any of these.")

As a newbie to Django, I encountered the same problem as many before me. I would appreciate if you didn't mark my question as a double immediately because I checked the fixes those old posts suggested but to no avail.
I was following this tutorial and have finished with all up to the heading "Projects App: Templates". Now when I start the server, at http://localhost:8000/ I get:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/
Using the URLconf defined in personal_portfolio.urls, Django tried these URL patterns, in this order:
admin/
projects/
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.
This is console output when I run server:
System check identified no issues (0 silenced).
April 05, 2019 - 15:31:54
Django version 2.2, using settings 'personal_portfolio.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Not Found: /
[05/Apr/2019 15:32:01] "GET / HTTP/1.1" 404 2042
Not Found: /favicon.ico
[05/Apr/2019 15:32:01] "GET /favicon.ico HTTP/1.1" 404 2093
What I tried, but didn't help:
restarting the server,
checking my code inside the files against the tutorial's source code,
Made sure that 'projects' is inside the INSTALLED_APPS list in settings.py.
Here is urls.py that's inside rp-portfolio\personal_portfolio:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('projects/', include('projects.urls'))
]
Here is urls.py that's inside rp-portfolio\projects:
from django.urls import path
from . import views
urlpatterns = [
path("", views.project_index, name="project_index"),
path("<int:pk>/", views.project_detail, name="project_detail"),
]
In the urls.py
from django.urls import path
from django.views.generic import RedirectView
urlpatterns = [
path('admin/', admin.site.urls),
path('projects/', include('projects.urls')),
path('', RedirectView.as_view(url='/projects/')),
]
try this
in urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('projects.urls'))
]
hope it helps
as you are seeking a path inside project your requested path must be this http://localhost:8000/projects/
You need to add:
in polls/urls.py
add this: from django.conf.urls import url
so it shold look like:
from django.urls import path
from django.conf.urls import url
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
Sometimes the URL picks up other words from the terminal.
Example 1.0
Starting development server at http://127.0.0.1:8000/Quit the server with CTRL-BREAK.
For instance in Example 1.0, instead of opening a link like http://127.0.0.1:8000/
The link will be http://127.0.0.1:8000/Quit since /Quit is not included as part of your code you will get the 404 error.
Example 2.0
Starting development server at http://127.0.0.1:8000/
Quit the server with
CTRL-BREAK.
Not Found: /Quit
[27/May/2021 22:36:07] "GET /Quit HTTP/1.1" 404 2066
[27/May/2021 22:36:59] "GET / HTTP/1.1" 200 5873
[27/May/2021 22:37:04] "GET / HTTP/1.1" 200 5873
Hope you find this helpful.

django-registration "reset" redirects to "login"?

django-registration 'reset' doesn't get processed
Using django-registration 1.0 under Django 1.6 . Everything (register, login, logoff, change) works as it should except "reset" which just redirects to the login form.
My urls.py looks like this :
urlpatterns = patterns('',
url(r'^spellweb/', include('spellweb.urls', namespace="spellweb")),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('registration.backends.default.urls')),
)
And the url associated with the 'Reset' link is :
http://localhost:8000/accounts/password/reset/
When that url is presented to the server a 302 is returned which sends the browser off to the login page like this :
[24/Feb/2014 22:55:00] "GET /accounts/password/reset/ HTTP/1.1" 302 0
[24/Feb/2014 22:55:01] "GET /accounts/login/?next=/accounts/password/reset/ HTTP/1.1" 200 1795
[24/Feb/2014 22:55:01] "GET /style.css HTTP/1.1" 302 0
[24/Feb/2014 22:55:01] "GET /accounts/login/?next=/style.css HTTP/1.1" 200 1780
[24/Feb/2014 22:55:01] "GET /accounts/login/?next=/favicon.ico HTTP/1.1" 200 1782
Just to make myself entirely clear the problem isn't just that the reset form isn't processed - the system won't even serve a 'reset' form .
So ... I'd be greatful if someone would suggest why this might be happening and/or confirm that they get some other result using Django 1.6/django-registration 1.0.
Thanks
More information pertinent to Mario Gudelj:
Yes I believe I am using the auth_urls you reference. The reason I say this is that the 'registration.backends.default.urls' referenced within my urls.py in turn references 'registration.auth_urls' . I don't know why that's not producing the effect I would expect. I would like to be sure that the url object within that auth_urls is being used but I can't find a way of establishing which django.conf.urls.patterns instance is active for any given request - that would be great if I could find a way of doing that.
More information pertinent to comment of Alasdair:
The ROOT_URLCONF points at the urls.py shown above which in its entirety is as follows:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
#url(r'^accounts/', include('auth_urls')),
urlpatterns = patterns('',
url(r'^spellweb/', include('spellweb.urls', namespace="spellweb")),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('registration.backends.default.urls')),
)
~
The spellweb.urls referenced there is as follows (nothing very much due to trying to get registration working before doing anything else) ...
from django.conf.urls import patterns, url
from spellweb import views
urlpatterns = patterns('',
url(r'^$', views.IndexView.as_view(), name='index'),
)
# url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'),
# url(r'^(?P<pk>\d+)/results/$', views.ResultsView.as_view(), name='results'),
~
The registration.backends.default.urls refernenced there is as per :https://bitbucket.org/ubernostrum/django-registration/src/8f242e35ef7c004e035e54b4bb093c32bf77c29f/registration/backends/default/urls.py?at=default and that in turn references : https://bitbucket.org/ubernostrum/django-registration/src/8f242e35ef7c004e035e54b4bb093c32bf77c29f/registration/auth_urls.py?at=default
Are you using https://bitbucket.org/ubernostrum/django-registration/src/8f242e35ef7c004e035e54b4bb093c32bf77c29f/registration/auth_urls.py?at=default?
It seems for that auth_urls.py has that URL and it's using Django's generic password_reset view from django.contrib.auth.views.
Make sure that you haven't changed the URL structure in that file and that this code is still in there:
url(r'^password/reset/$',
auth_views.password_reset,
name='auth_password_reset'),
Seems like you have somehow managed to place login_required decorator around that view.

Categories

Resources