【发布时间】:2018-11-25 18:05:23
【问题描述】:
我是 Django 新手,正在尝试构建具有以下结构的 Web 应用程序。我需要你的帮助来了解我做错了什么。
应用程序的流程是 shadesProductUploader.urls 将 '' 转发到 authSection 以进行登录 并在成功登录后将用户重定向到 mainSection 'home /'.
Urls.py 文件是
shadesProductUploader.urls
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('authSection.urls')),
]
authSection.urls
from django.contrib import admin
from django.urls import path, include
from . import views
app_name = 'authSection'
urlpatterns = [
path('', views.login_view, name='login'),
]
mainSection.urls
from django.contrib import admin
from django.urls import path,include
from . import views
app_name = 'mainSection'
urlpatterns = [
path('home/', views.home),
]
和 authSection 中的 view.py
def login_view(request):
next = request.GET.get('next')
form = userLoginForm(request.POST or None)
if form.is_valid():
username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password')
user = authenticate(username=username,password=password)
login(request,user)
if next:
return redirect(next)
context={'user':user}
return redirect('home/')
return render(request, 'login.html', {'form': form})
成功登录后出现此错误。
我错过了什么?不知道为什么我会看到 home/home/ 的网址
【问题讨论】:
标签: django django-urls