How to resolve error in URL configuration in Django?

Asked

Viewed 97 times

0

I’m starting to learn Jango(or trying) but I can’t solve the following problem:

"Using the Urlconf defined in Sitejg.urls, Django tried These URL Patterns, in this order:

Templates/main.html

The Empty path didn’t match any of These."

py Settings.:

ROOT_URLCONF = 'SiteJG.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['templates/'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

py.:

from django.urls import path
from django.views.generic import TemplateView

urlpatterns = [
    path('templates/', TemplateView.as_view(template_name='main.html'))
]

1 answer

0


I’m not sure what you’re doing, but in your project folder you have to have a folder that says templates, something like this :

   ├── MEU PROJETO
   │   └── settings.py
   └── manage.py
   |___PASTA DA APP
   |
   └── templates

Next on settings.py you have to include the folder :

 'DIRS': [os.path.join(BASE_DIR, 'templates')],

Then you’ll have to go to your app and you’ll have a file views.py

from django.shortcuts import render

def index(request):
    return render(request, 'main.html')

Next, just include this view that we created in urls.py

from . import views

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.