Page Not Found 404 Django & Python - django

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

Related

Django -Page not found (404) Request Method: GET Method

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

Django 2.2 default login url

I want to load the Django builtin login page, but not with the URL http://127.0.0.1:8000/login/, instead of this i am trying to load the login page like this URL http://127.0.0.1:8000/
I have tried :
LOGIN_URL ='/login/' - (in settings.py)
#login_required()- (in the app view.py)
#login_required(login_url='/login/') - (in the app view.py)
these both method not helped me, kindly someone help me to sort this out.
project url.py
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('home.urls')),
]
project settings.py in the bottom i have included like below
LOGIN_URL='/login/'
LOGIN_REDIRECT_URL= 'home'
LOGOUT_REDIRECT_URL ='home'
in my app url
#
from django.urls import path, include
from home.views import HomeView
urlpatterns = [
path('',include('django.contrib.auth.urls')),
path('home',HomeView, name='home'),
]
in app view.py
from django.http import HttpResponse
from django.shortcuts import render
#login_required(login_url='/login/')
def HomeView(request):
return render(request, "home.html")
overall my expectation to load the Django default Login page without passing /login/ or account/login in the url.
you can use a generic class
from django.contrib import admin
from django.urls import path, include
from django.views.generic.base import RedirectView
urlpatterns = [
path('', RedirectView.as_view(url='/admin/'), name='django_admin'),
path('admin/', admin.site.urls),
path('other/', include('other.urls')),
]
https://docs.djangoproject.com/en/2.2/ref/class-based-views/base/
You can try change '/login/' for '' in all files.

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

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

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

404 Error while accessing API with tastypie

Just started with TastyPie to expose the data. Trying to tie together resources using tastypie.Api for urls.py.
But I get this error when I try to access them through localhost:api/**resource.
my api.py:
from tastypie.resources import ModelResource
from idg.models.molecule_dictionary import MoleculeDictionary
class MoleculeDictionaryResource(ModelResource):
class Meta:
queryset = MoleculeDictionary.objects.all()
# resource_name = 'moleculedictionary'
my url.py:
from django.conf.urls import url, include, patterns
from idg.api import MoleculeDictionaryResource
from django.contrib import admin
from tastypie.api import Api
from . import views
dictionary_resource = MoleculeDictionaryResource()
# private_api = Api(api_name='private')
# private_api.register(MoleculeDictionaryResource(), canonical=True)
urlpatterns = [
url(r'^$', views.index, name='index'),
# url(r'^exports/', include('data_exports.urls', namespace='data_exports')),
url(r'^api/', include(dictionary_resource.urls)),
]
Error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/api/moleculedictionary/?format=json
Using the URLconf defined in django_root.urls, Django tried these URL patterns, in this order:
^__debug__/
xadmin/
^idg/
^comments/
^admin/
The current URL, api/moleculedictionary/, 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.
Any suggestions ? I am not sure where I made a mistake. I have followed the tutorial (https://django-tastypie.readthedocs.org/en/latest/tutorial.html)
Uncomment line
resource_name = 'moleculedictionary'
in Your api.py file.
Try this:
private_api = Api(api_name='v1')
private_api.register(MoleculeDictionaryResource(), canonical=True)
url(r'^api/', include(private_api.urls)),
Then you should be able to access it with /api/v1/