urls.py 在 app1.
from django.contrib import admin
from django.urls import path
from . import views
app_name = 'cricprofile'
urlpatterns = [
path('', views.home, name="home"),
path('<int:player_id>',views.detail, name="detail")
]
views.py 在 app2.
from django.shortcuts import render,redirect
from django.contrib.auth.forms import UserCreationForm
from django.contrib import messages
def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
messages.success(request,f'Welcome {username}, Your account created Successfully')
return redirect('cricprofile:index.html')
else:
form = UserCreationForm()
return render(request,'users/register.html',{'form':form})
我在 django 中创建了一个包含两个应用程序的项目。
实际问题是当我尝试从一个应用程序访问 html 模板时无法重定向到另一个应用程序。
当我尝试重定向时出现此错误 找不到“索引”的反转。 “索引”不是有效的视图函数或模式名称
我认为你必须改变这个:
return redirect('cricprofile:index.html')
通过以下内容:
return redirect('cricprofile:home')