Page not found on Django - Empty paths - python

I'm trying to run this library. I downloaded and copied it on my desktop, then i tried to run it using:
py -3.7 manage.py runserver
I got:
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
But when i go to that url i keep getting this error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in django_google_authenticator.urls, Django tried these URL patterns, in this order:
^admin/login/$
^admin/
The empty path didn't match any of these.
I don't understand what's wrong, can someone help me? Thanks in advance!

I think thats the normal behavour of Django, as you can see it is saying that your path didn't match any of the configured ones, like admin, so why don't you try http://127.0.0.1:8000/admin/to access Django Admin login page.
If you want to see something different from a 404 with the base url you need to configure your urls and maybe add a redirect view, in that way when the base url is use it will redirect to your admin or other preferred page.

Related

How to fix exception 404 in Django views?

I'm following this tutorial:https://www.w3schools.com/django/django_views.php
After copying all the code to create the members and admin views I get this error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in myworld.urls, Django tried these URL patterns, in this order:
members/
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.
In your project urls.py you set the path to the members app to use 127.0.0.1:8000/members
In order to navigate to 127.0.0.1:8000/members using the default route, you need to change the path to look like this :
path('', include('members.urls')),

Django odd behaviour

Whenever I start a project in Django, independently of the name of the app or project, and irrespective of any urls or settings configuration, upon running python manage.py runserver and navigating to 127.0.0.1 I get the following error: Not Found: /ball/ [10/Jan/2022 11:32:32] "GET /ball/ HTTP/1.1" 404 2337 and this displays in th browser:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/ball/
Using the URLconf defined in ornaments.urls, Django tried these URL patterns, in this order:
admin/
^static/(?P<path>.*)$
^media/(?P<path>.*)$
^static/(?P<path>.*)$
The current path, ball/, 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.
Why is Django looking for a route called ball?

Page not found error in django where it is not supposed to rise

I am building a video player app in django. But, when going to the register route, I get this error:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/users/login/%7B%25%20url%20'register'%20%7D
I don't even have a url called users/login/register. And I have checked my urls.py. Here it is:
urlpatterns = [
path('register/',views.register,name='register'),
]
And here is the link that leads to this route:
Register
I have built many apps with django but have never encountered an error like this. Why am I getting this error?
You are missing a % in your a tag, it should be
Register
Does this solve your problem?
probably, url is not recognized because of absence "%" before brace in the last line.
Register

Django trying to match wrong url path

Trying to deploy my Django app on virtual shared server. All works as expected until I try to log in to the admin app. I think it may have something to do with the way that the server deals with posts (had a similar problem with Flask). The setup works fine on my local machine.
I can get to the admin login page, but when I submit my credentials I get a 404 error. In debug mode the response is:
Page not found (404)
Request Method: POST
Request URL: https://lindcraft.williesworkshop.com/admin/login/
Raised by: django.contrib.admin.sites.login
Using the URLconf defined in lindcraft.urls, Django tried these URL patterns, in this order:
admin/
^[P|p]roducts?/(?P<prod_id>\d{0,3})/$ [name='product']
^[P|p]rices?/?$ [name='prices']
^[P|p]arking [name='parkingIntro']
^[D|d]isplay [name='displayIntro']
^[C|c]ontact [name='contact']
^[A|a]bout [name='about']
^$ [name='index']
The current path, login/, didn't match any of these.
The project urls.py is:
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('www.urls')),]
Django seems to be looking for "login/" instead of "admin/" even though the "request URL" is "... /admin/login/" The admin part is striped off somehow.
Funny thing is, the exception seems to be raised by django.contrib.admin.sites.login as though the request actually made it to admin.
It seems to me that the same URL works with a GET but not with a POST.
Can anyone offer any insight?
FWIW, my hosting service (a2hosing) uses something called passenger to manage python requests. There may, or may not be a ngnix server used too.
TIA!

django admin returns 403 csrf error

I am producing a django/angular project. Django being the backend administration and Angular being the frontend/public display. I have created a Django 1.11 app and loaded all files, installed dependencies, etc. Locally, the site works fine and as expected. Also, since forms will be Angular js I commented out the django.middleware.csrf.CsrfViewMiddleware in my settings.py which I thought would disable the csrf token even being needed, but apparently not.
After setting up server and installing files the admin login page appears but I get the following error when I try and login:
Forbidden (CSRF token missing or incorrect.): /admin/login/
Any ideas on why this is happening would be greatly appreciated.
You can't commented out the 'django.middleware.csrf.CsrfViewMiddleware' in your settings.py, The CSRF middleware provides easy-to-use protection against Cross Site Request Forgeries. Since you are using Augualr js instead of django forms and views, you can set the csrftoken cookie in your browser cookies. Check this for detail: https://docs.djangoproject.com/en/1.11/ref/csrf/#module-django.middleware.csrf

Categories

Resources