I tried to create an django hello world program then I got this error - django

from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('love/', include('love.urls')),
path('admin/', admin.site.urls),
]
I tried this code by seeing n online documentation and I see the code as same as the one in the documentation but I see the error and I can not start practicing django.
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('love/', include('love.urls')),
path('admin/', admin.site.urls),
]
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in ad.urls, Django tried these URL patterns, in this order:
^love/
^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.
It is being shown on the web

you must define empty path to use 127.0.0.1:8000
path('', include('love.urls')),

Related

Page not found at/admin

I'm a very beginner.
When I tried to go visit this (http://127.0.0.1:8000/admin), I couldn't. Here have shown page not found. What can be the solution?
Problem that I faced:
Page not found (404)
“D:\1_WebDevelopment\Business_Website\admin” does not exist
Request Method: GET
Request URL: http://127.0.0.1:8000/admin
Raised by: django.views.static.serve
Using the URLconf defined in business_website.urls, Django tried these URL patterns, in this order:
admin/
admin/
[name='index']
singup [name='handle_singUp']
login [name='handle_login']
logout [name='handle_logout']
contact [name='handle_contact']
frontend_orders [name='frontend_orders']
hire_me [name='hire_me']
^(?P<path>.*)$
The current path, admin, matched the last one.
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.
Problem : open the picture
business_website urls.py:
from django.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('business_app.urls')),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
business_website url.py : open the picture
business_app urls.py:
from os import name
from django.contrib import admin
from django.urls import path
from .import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index, name="index"),
path('singup', views.handle_singUp, name= "handle_singUp"),
path('login', views.handle_login, name="handle_login"),
path('logout', views.handle_logout, name="handle_logout"),
path('contact', views.handle_contact, name="handle_contact"),
path('frontend_orders', views.frontend_orders, name="frontend_orders"),
path('hire_me', views.hire_me, name="hire_me")
]
business_app url.py : open the picture
Delete from business_app urls.py this row:
path('admin/', admin.site.urls),
You should not call it twice.
You should set MEDIA_URL in settings to something. Like:
MEDIA_URL = '/media/'
Django urls need to have a trailing slash and the url you tried to access does not have it, check in your settings.py file if APPEND_SLASH is set to false
Among Django's many built-in features is APPEND_SLASH, which by default is set to True and automatically appends a slash / to URLs that would otherwise 404.
You can turn off this option by just setting APPEND_SLASH = False
You can read more here about why django uses trailing slashes
You have the same admin path defined in your root urls.py and in your app. It should probably be in just the root. Remove it from:
from os import name
from django.contrib import admin
from django.urls import path
from .import views
urlpatterns = [
# path('admin/', admin.site.urls), ##### REMOVE
path('', views.index, name="index"),
path('singup', views.handle_singUp, name= "handle_singUp"),
path('login', views.handle_login, name="handle_login"),
path('logout', views.handle_logout, name="handle_logout"),
path('contact', views.handle_contact, name="handle_contact"),
path('frontend_orders', views.frontend_orders, name="frontend_orders"),
path('hire_me', views.hire_me, name="hire_me")
]
Edit
After trying, and failing to reproduce the OP's error on my machine using all the answers given as of this writing, it turned out my original answer was not correct (not incorrect, but also not the solution), in fact the original answer given by Jaime Ortiz, was most likely the correct one.
But why was it so hard to come to this realization? Within the link he provided was this, which is why, when I initially tried his solution it did not work. Below is from the answer provided by
All Іѕ Vаиітy in that link. Note that within the [] is my insertion.
Since django observes both the urls [the one with the trailing slash
and the one without] as different, if you are caching your app, Django
will keep two copies for same page at ...
So either use admin/ instead of admin, or apply APPEND_SLASH = False to your settings.py, clear your browser cache and then you can use either, Django will append the slash automatically.

Page Not Found 404 Django & Python

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 new at Django and kept being stuck at the ERROR 404 (Page Not Found)

Using the URLconf defined in firstProject.urls, Django tried these URL patterns, in this order: index/ [name='main-view'] admin/ The empty path didn’t match any of these.
from django.contrib import admin
from django.urls import include,path
from firstApp import views
urlpatterns = [
path('index/',views.index, name = 'main-view'),
path('admin/', admin.site.urls),
]
You don't have a url pattern for the empty route, hence, you are getting ERROR 404.
Change
path('index/',views.index, name = 'main-view'),
to
path('',views.index, name = 'main-view'),
in your urlpatterns list and your index view defined in your views.py will run.

Django polls app is not working as expctected in the tutorial for me

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',
]

Django page not found error

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.