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 = [
# ↓↓ empty string
url('', include('polls.urls')),
url('admin/', admin.site.urls),
]
Related
I am a total beginner in "django" so I'm following some tutorials currently I' am watching https://youtu.be/JT80XhYJdBw Clever Programmer's tutorial which he follows django tutorial
Everything was cool until making a polls url
Code of views.py:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
HttpResponse("Hello World.You're at the polls index")
Code of polls\urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
Code of Mypr\urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/',admin.site.urls),
path('polls/',include('polls.urls')),
]
I don't get it I did the same thing but I'm getting error not only polls.In one turtorial he decided to make blog,and again the same error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/polls/
Using the URLconf defined in Mypr.urls, Django tried these URL patterns, in
this order:
admin/
The current path, polls/, didn't match any of these.
Please my seniors help me.
Note:I'm using the latest versions of django,windows and as editor I'm using Pycharm.
Already tried(and did not work):
from django.urls import path
from polls.views import index
urlpatterns = [
path('', index, name='index'),
]
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/polls/
Using the URLconf defined in Mypr.urls, Django tried these URL patterns, in this order:
admin/
The current path, polls/, 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.
try to access polls/ URL in your browser then you will access the page
Because you have accessed the URL of your project, you have to go to this URL to access your app
try by changing your code like this
from django.urls import path
from polls.views import index
urlpatterns = [
path('', index, name='index'),
]
I was facing the same error. Feel kinda dumb after figuring out how to solve this.
Your urls.py content is all right
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
But it must be included in the mysite\mysite\urls.py and not in mysite\urls.py.
That means the inner mysite/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it.
I am new to Django and I am trying to build an image classifier app, I just tried building the app but I am getting this error, how may I resolve it?
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/imageupload
Using the URLconf defined in imageclassifier.urls, Django tried these URL patterns, in this order:
imageupload ^$ [name='home']
admin/
The current path, imageupload, 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.
These are all changes I made in my app:
This is the views.py file in imgUpload app
from django.shortcuts import render
# Create your views here.
def home(request):
return render(request, 'home.html')
This is the urls.py file in imageUpload app
from django.contrib import admin
from django.urls import path,include
from . import views
urlpatterns = [
path('^$', views.home, name ='home'),
]
And this is the urls.py in the Imageclassifier folder:
"""imageclassifier URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('imageupload', include('imgUpload.urls')),
path('admin/', admin.site.urls),
]
Also, I have added a home.html file in the templates folder. How may I fix this error?
In the latest django path methods, You do not need to use ^$ in your path. Simply remove that ^$ from your path and it will work fine.
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
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.
This question already has answers here:
The current URL, app/, didn't match any of these
(10 answers)
Closed 5 years ago.
Page not found (404)
Request Method: GET>br>
Request URL: http://127.0.0.1:8000/votes/
Using the URLconf defined in votes.urls, Django tried these URL patterns, in this order:
^$ [name='index']
The current path, votes/, 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 urls.py of my app.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
this is my urls of my entire project
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^votes/', include('votes.urls')),
url(r'^admin/', admin.site.urls),
]
I tried to approach to admin site but i couldn't. how can I fix it?
In your app urls.py your saying that: http://127.0.0.1:8000/ should call votes.views.index not http://127.0.0.1:8000/votes/, so you need to change it to:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^votes/$', views.index, name='index'),
]