URL encoded characters on clicking link and page not found - python

I am getting the following error using Django 2.1:
Page not found (404)
Request Method: POST
Request URL: http://localhost:8000/user-accounts/%5Eregister/
Using the URLconf defined in my_project.urls, Django tried these URL patterns, in this order:
admin/
user-accounts/ ^register/$ [name='register']
user-accounts/ ^login/$ [name='login']
user-accounts/ ^logout/$ [name='logout']
bank-accounts/
The current path, user-accounts/^register/, didn't match any of these.
When I click a link in the header set in my base.html, I get the strange url http://localhost:8000/user-accounts/%5Eregister/ in browser. The links in base.html are:
<li class="dropdown-header">Register</li>
<li class="dropdown-header">Login</li>
The user accounts app urls.py:
from django.urls import path
from django.contrib import admin
from . import views
app_name = 'user-accounts'
urlpatterns = [
path(r'^register/$', views.register, name='register'),
path(r'^login/$', views.user_login, name='login'),
path(r'^logout/$', views.user_logout, name='logout'),
]
The project urls.py:
from django.contrib import admin
from django.urls import path, include
from user_accounts.views import register
urlpatterns = [
path('admin/', admin.site.urls),
path('', register),
path(r'user-accounts/', include('user_accounts.urls')),
path(r'bank-accounts/', include('bank_accounts.urls')),
]

Django's new (>=2.0) path() function does not work with regular expressions. That's why the ^ character is literally prepended to the URL.
If you want to keep using regular expressions, use the re_path() function.

Related

The empty path didn't match any of these:

i am using python 3.8 and getting error when i launch server:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in djangoProject.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.
my polls/urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
my djangoProject/urls.py:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url("polls/", include('polls.urls')),
url("admin/", admin.site.urls),
]
The root urls contains two items: polls/ and admin/. This thus means that if you visit the root URL (127.0.0.1:8000/), it will not trigger any view, since no view has been "attached" to that URL pattern. You thus will have visit a page to trigger the view, or change the URL patterns to enable visiting the index view if you visit the root URL.
Option 1: visit /polls/
You can visit the page by visiting:
127.0.0.1:8000/polls/
Option 2: link index to the root URL
You can change the URL patterns to trigger index when visiting the root URL with:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
# &downarrow;&downarrow; empty string
url('', include('polls.urls')),
url('admin/', admin.site.urls),
]

Django page not found, help would be appreciated

I was taking a youtube tutorial on making a basic website using django and I got this error when coding:
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:
app/
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.
This is my code:
For urls.py/mysite:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('app/', include('myapp.urls')),
path('admin/', admin.site.urls),
]
For views.py:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world!")
For urls.py/myapp:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
You need to add root level path to access the path you specified http://127.0.0.1:8000/:
urls.py/mysite
urlpatterns = [
path('', views.index, name='home'),
path('app/', include('myapp.urls')),
path('admin/', admin.site.urls),
]
views.py/mysite
def index(request):
return HttpResponse('This is home page')
Since you specified:
path('app/', include('myapp.urls')),
It means all the paths in myapp.urls are prefixed with app/. So you can access the index view with: http://127.0.0.1:8000/app/. Or if you want to access the index view with http://127.0.0.1:8000/ you rewrite the path to:
path('', include('myapp.urls')),

Page not Found (404) in django

Am using django I got this error Page not Found (404) Request Method: GET Request URL: http://127.0.0.1:8000/ Using the URLconf defined in VibezT.urls, Django tried these URL patterns, in this order
music/
admin/
The empty path didn't match any of these.
VibezT\urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns =[
path('music/', include('music.urls')),
path('admin/', admin.site.urls),
]
For music URLs I have this code
music\urls.py
from django.urls import path
from . import views
urlpattern = [
path(r'^$',/ views.index, name='index')
]
For views i have this code
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World")
You have not defined a URL for / in your code. Your code is defined for music/
You need to go to http://127.0.0.1:8000/music/ to find your view.
Also, I do not know why you are structuring your URL like this if you are using path. path(r'^$',/ views.index, name='index')
Just replace that with this:
path('', views.index, name='index'),
in your music\urls.py

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order

I have a problem with Django. Actually I want to create a login panel in my new site but when I try to write address the debugger respond me a error:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/account/login
Using the URLconf defined in firmowa.urls, Django tried these URL patterns, in this order:
admin/
^account/
The current path, account/login, didn't match any of these.
My firmowa.urls is
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path(r'^account/', include('account.urls')),
]
And the project urls.py is:
from django.urls import path
from . import views
urlpatterns = [
path(r'^login/$', views.user_login, name='login'),
]
I'm looking a solution from few hours but still nothing.
path is a new feature in Django 2.0 and works different than the old url. Don't use regex in path. If you need regex, use re_path instead, but in your case there's no need for that.
Change your code to:
urlpatterns = [
path('login/', views.user_login, name='login'),
]
etc. and it should work.
More on the topic here and here.
from django.urls import path
from . import views
from django.conf.urls import url
urlpatterns = [
url( r'^$', views.index , name='index') ,
]

Django can't find social auth url pattern

I have tried to set up social authentication for steam login button. I have followed all these steps, and added steam necessary stuff: adding API key to settings and steam.SteamOpenId to authentication backends.
The error:
Using the URLconf defined in Test.urls, Django tried these URL patterns, in this order:
^ ^$ [name='index']
^login/(?P<backend>[^/]+)/$ [name='begin']
^complete/(?P<backend>[^/]+)/$ [name='complete']
^disconnect/(?P<backend>[^/]+)/$ [name='disconnect']
^disconnect/(?P<backend>[^/]+)/(?P<association_id>[^/]+)/$ [name='disconnect_individual']
^admin/
Hyperlink i used to make login button:
Login
urls.py file of project:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^', include('Home.urls')),
url('', include('social.apps.django_app.urls', namespace='social')),
url(r'^admin/', admin.site.urls),
]
urls.py file of application Home:
from django.conf.urls import url
from . import views
app_name = 'Home'
urlpatterns = [
url(r'^$', views.index, name='index'),
]
Full Project Here.
I am wondering if there is still something that i need to set up, do i need to add views to url patterns? If so, then which? where is social authentication urls file located?

Categories

Resources