page not found django 2.0.2 python 3.5

0

I request of your wisdom and wisdom to determine the reason that you receive the famous 404 error when I try to load my web pilot in Django, the difference that I have in relation to this same topic already explained several times is that I in the urls. py did not indicate the pages with url, but now django indicates that it is with path, and when executing the server it indicates to me that everything is correct, nevertheless when trying to load the page I receive that error.

I thank you in advance for your attention and support.

    
asked by Fernando Tlatilolpa Martinez 20.02.2018 в 06:24
source

1 answer

1

The problem you have is that you are using regular expressions in path () that is new to Django 2 as you indicated. this only understands url addresses written in the common form, example 'myapp / index /', if you want Django to understand the routes with regular expressions you should define them with re_path (). In your case it would be

from django.urls import re_path

re_path(r'^$',views.index,name='index')

Assuming you have a Django project where you have created an app called myapp with an index view, your urls.py of the general project should look like this:

from django.urls import include, path
from django.contrib import admin

urlpatterns = [
    path('admin/', admin.site.urls),
    path('myapp/', include('myapp.urs'), /aqui especificas las urls de myapp/*
]

and in your application (in this case myapp) you create a file called urls.py and if it does not exist where you will put the routes belonging to that specific app that would be as follows.

from django.urls import path
from myapp import views

    urlpatterns = [
        path('', views.index, name='index'),           
    ]

if you remember in urls.y of the general project we declare path('myapp/', include('myapp.urs') this means that whatever myapp / go to urls.y of myapp and resolves, in my app there is an empty path path('', views.index, name='index'), that calls index , so when you put localhost:8000/myapp you should leave the index view

    
answered by 23.02.2018 / 14:20
source