Correctly set URLS in Django

Asked

Viewed 101 times

0

I need to make two pages

login and Challenge, where urls can be domain/login and domain/challenge or domain/login/challenge

Only the way I’m doing is giving 404

Files from the APP: py views.

from django.shortcuts import render

def login(request):
  return render(request, 'login.html', {})

def challenge(request):
  return render(request, 'challenge.html', {})

py.

from django.urls import path
from . import views

urlpatterns = [
  path('login/', views.login, name='login'),
  path('challenge/', views.challenge, name='challenge'),
]

Project files:

py.

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

urlpatterns = [
    path('admin/', admin.site.urls),
    path('login/', include('login.urls')),
]

What am I doing wrong?

Remembering that I’m a beginner in python, and I’m studying.

1 answer

0


As you used a include in the project’s main urls.py, you will need to access the Domain/login/login or Domain/login/Challenge address, if you want to change this, you can access the main urls.py file and do the following::

from django.contrib import admin
from django.urls import path
from login import views as login_view

urlpatterns = [
    path('admin/', admin.site.urls),
    path('login/', login_view.login, name='login'),
    path('challenge/', login_view.challenge, name='challenge'),
]

When you add a route through include, as in your case, you can only access if you use what’s inside the path, in your case it’s "login".

  • Resolvei buddy vlw.

Browser other questions tagged

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