Runserver: " Not Found: / " - django

I executed runserver to test Django Framework but it appears a message " Not Found: / ". When I try the page localhost:8000 it works fine, but the message is still there. Any idea?
P.S. I tried localhost:8000/admin and the message does not appear.
Urls.py
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
]

This happens simply because you didn't define any pattern in urls.py that matches / and you have some views that matches admin/.
If you want to show something in http://127.0.0.1:8000/ you will need to create a view first and add it to urls.py like
`url(r'^$', 'myview', name='myview'),``
I recommend you to follow the Django tutorial

Related

Django flatpages The empty path didn't match any of these

On the administration page, I set the URL for the Django flat pages to "/", which is expected to be displayed as the home page at http://127.0.0.1:8000/. Doing so I encountered an error:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in core.urls, Django tried these URL patterns, in this order:
admin/
<path:url>
The empty path didn't match any of these.
But if I go to http://127.0.0.1:8000// with double slash then the home page is displayed correctly. My only urls.py file looks like this:
from django.contrib import admin
from django.urls import include, path
from django.contrib.flatpages import views
urlpatterns = [
path('admin/', admin.site.urls),
]
urlpatterns += [
path('<path:url>', views.flatpage),
]
And I took all the code completely from the official guide. How to display the django flatpage homepage at http://127.0.0.1:8000/?
In addition to the django.urls.path method Django offers the django.urls.re_path method. The path method is designed to perform matches against exact strings, whereas the re_path method is designed to perform matches against patterned strings based on regular expressions. In my case it’s enough to fix it this way:
urlpatterns += [
re_path(r'^(?P<url>.*)$', views.flatpage),
]
As a result, we get the correct processing of requests at http://127.0.0.1:8000/. More details about using path, re_path methods can be found at the link.

Page not found after trying to add a new path to the urlpatterns of main urls.py file? (Mosh Python Tutorial)

I'm following Mosh's tutorial video on Python. He begins the django section (https://youtu.be/_uQrJ0TkZlc?t=18085) by installing django 2.1. I am able to open a development server the first time as he does:
pip install django==2.1
django-admin startproject pyshop .
python manage.py runserver #server works
Here are the steps he goes through to add a "products" app/path:
python manage.py startapp products
Opens views.py from this new products folder and modifies code to this:
from django.http import HttpResponse
from django.shortcuts import render
def index(request):
return HttpResponse('Hello World')
Creates urls.py inside the products app/folder and adds this code:
from django.urls import path
from . import views
urlpatterns = [
path(' ', views.index) # Here should have been '' and now fixed
]
Opens the main urls.py in the pyshop folder and adds/modifies the end of the file like this:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('products/', include('products.urls'))
]
Mosh goes back to the server and adds /python to the url to get a page with "Hello World"
(https://youtu.be/_uQrJ0TkZlc?t=19220)
Upon trying to run the server again, I get Page not found error. Is there something I'm missing? I didn't figure it'd be a version issue since I made sure and installed the same 2.1 version.
As Jeffery and Daniel mentioned, I had an incorrect space and it needed to be an empty string in the products urls.py path. However, I'm still getting page not found error. Here's the exact error message if that helps:
Using the URLconf defined in pyshop.urls, Django tried these URL patterns, in this order:
admin/
products/
The empty path didn't match any of these.
Modify your url path in the products app/folder like this
urlpatterns = [
path('', views.index)]
Remove the space in between

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 URLs management

I'm a full beginner on Django. Therefore, I'm sorry if my question is not making so much sense.
I'm studying Django tutorial - step 1. I installed properly Django and created my first Django project named 'vanilla'. The urls.py script of the vanilla project is
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
When I start Django with this 'vanilla' project and start the development server at http://127.0.0.1:8000/, I correctly see the start page (with a rocket).
In a second project that I named 'djtutorial', I created as requested in Django tutorial - step 1 a 'polls' app. As requested, I modified urls.py file in djtutorial\polls which now has following content:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
If I start the server the url http://127.0.0.1:8000/polls/ is working properly. However, if I launch the root url of the site (i.e. http://127.0.0.1:8000/), I now have a 404 error.
Why is the 'root url' of the site now hidden?
There wasn't any root URL at all. Main page informing you that your project is created properly shows up only if you don't have any view of your own added to urlpatterns. When you create any page, this welcome page stops showing up and that is expected.
If you want to show your own page on root of your website, use this in your urlpatterns:
path('', >>VIEW OR INCLUDE HERE<<),

Django urls.py not updating to include heroku url?

I am trying to deploy my Django app on Heroku and I am following the tutorial but when I go and try to open the website with:
heroku open
I receive the error :
Request URL: http://nameless-dawn-7713.herokuapp.com/
Using the URLconf defined in crunchWeb.urls, Django tried these URL patterns, in this order:
^crunchApp/results$
^crunchApp/contact$
^admin/
The current URL, , didn't match any of these.
Even though before running " heroku open" my URLs.py file looks like this (saved) :
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('crunchApp.views',
url(r'^crunchApp/results$', 'results'),
url(r'^http://nameless-dawn-7713.herokuapp.com/$', 'contact'),
url(r'^crunchApp/contact$', 'contact'),
url(r'^admin/', include(admin.site.urls)),
)
I think I might have to change the urls.py before the command:
git commit -m "my django app"
but I dont know the URL that it will need until the command:
heroku create
Any ideas of what to do?
Why do you have url(r'^http://nameless-dawn-7713.herokuapp.com/$', 'contact') in your urls file ? In fact, these URLs should be relative to your application, and you should not update this file before uploading to Heroku (if it works locally, it should work on Heroku without any change to this file).
If you want to connect the contact view to your base URL (http://nameless-dawn-7713.herokuapp.com/), you should use something like:
url(r'^$', 'contact')
Hope this helps !