I am very new to Django ,I am trying to run a URL ,however I get this error of page not found.I went through almost 90% of the posts here but nothing worked for me.
Here are three .py files
views.py.....
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello world....')
**products\urls.py****
from django.urls import path
from . import views #.means current folder ,we are importing a module
urlpatterns=[
path(' ', views.index),
]
pyshop\urls.py.......
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('products/',include('products.urls'))
]
Error I get.....
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/products/
Using the URLconf defined in pyshop.urls, Django tried these URL patterns, in this order:
admin/
products/
The current path, products/, didn't match any of these.
I think you have to delete the space on the path :
urlpatterns=[
path(' ', views.index),
]
Like :
urlpatterns=[
path('', views.index),
]
Related
I am having the following error
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in Decoder.urls, Django tried these URL patterns, in this order:
form.html [name='form1']
hl7 [name='hl7']
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.
Its my first time writing code using Django
`from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', include('hl7rest.urls')),
]`
and this other file
from . import views
from django.urls import path
urlpatterns = [
path('form.html', views.render_form_View, name='form1'),
path('hl7', views.hl7_web_view ,name='hl7'),
]
Your paths don' t match the request.
You can create a TemplateView subclass for render your template:
Views
from django.views.generic.base import TemplateView
class HomePageView(TemplateView):
template_name = "display_form.html"
Url patterns
urlpatterns = [
path('', HomePageView.as_view(), name='home')
]
I am trying to make a certain url on my localhost show "Alex!" when it is entered in. For some reason I am getting this error: "Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
admin/
The current path, sauce, didn’t match any of these."
The app name is "main"
Here is my code:
main.urls
from django.urls import path
from . import views
urlpatterns = [
path('sauce/', views.index, name='index'),
]
main.views
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse("Alex!")
mysite.urls
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('sauce/', include('main.urls')),
path('admin/', admin.site.urls),
]
I also tried doing this but with the homepage and not "sauce/" but that didn't work either.
Your path is not matching because you have "sauce" in both main.urls and mysite.urls. When you use include the urls from main.urls will be appended to the path you specify in mysite.urls, so the combined url becomes:
http://127.0.0.1:8000/sauce/sauce
I would replace the "sauce/" in mysite.urls to just "".
I am getting this error every time restart my server
Page not found (404) Request Method: GET Request URL:
http://127.0.0.1:8000/polls/
Using the URLconf defined in mysite.urls, Django tried these URL
patterns, in this order: admin/ The current path, polls/, didn't
match any of these.
I have tried restarting the server but the same error is popping up every time.
polls/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name = 'index'),
]
mysite/urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("polls/", include("polls.urls")),
path("admin/", admin.site.urls)
]
views.py/polls
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello world. You're at the polls index.")
The expected result as per the Django tutorial is the text "Hello world. You're at the polls index." after you start your server
You probably didn't add your app polls to installed apps in your settings.py.
Open your file settings.py and write:
INSTALLED_APPS = [
....,
'polls',
]
Hello I am trying to solve the error which keeps on occurring;
my current code on mysite/urls.py is
from django.contrib import admin
from django.urls import path
from django.conf.urls import url
from polls import views
admin.autodiscover()
urlpatterns = [
url(r'^polls/$', views.index, name='index'),
url(r'^polls/(?P<question_id>\d+)/$', views.detail, name='detail'),
url(r'^polls/(?P<question_id>\d+)/vote/$', views.vote, name='vote'),
url(r'^polls/(?P<question_id>\d+)/results/$', views.results, name='results'),
url('admin/', admin.site.urls),
]
and I am getting error when I try to access :8001/polls
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8001/
Using the URLconf defined in mysite.urls,
Django tried these URL patterns, in this order:
^polls/$ [name='index']
^polls/(?P<question_id>\d+)/$ [name='detail']
^polls/(?P<question_id>\d+)/vote/$ [name='vote']
^polls/(?P<question_id>\d+)/results/$ [name='results']
admin/
The empty path didn't match any of these.
Please help me to solve this error which makes me cannot access to the website.
I still new to Django and I'm following this tutorial in YouTube. I can't proceed to the next tutorial because I hit an error.
When I type http://127.0.0.1:8000/music. I get this error.
Check my code below:
mysite urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^music/', include('music.urls')),
]
music urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
music views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("<h1>Hello World</h1>")
Please help.
You might have not saved the project/urls.py file.
Or to check whether the music is set in INSTALLED_APPS in settings.py?