Получение перенаправления на неверный url в django
Я пытаюсь отправить письмо с подтверждением учетной записи и перенаправить на страницу входа
def signup(request):
custom_user_id = ''.join(random.choices(string.ascii_uppercase+string.digits,k=10))
if request.method=="POST":
form = RegistrationForm(request.POST)
if form.is_valid():
first_name = form.cleaned_data['first_name']
last_name = form.cleaned_data['last_name']
email = form.cleaned_data['email']
password = form.cleaned_data['password']
username = form.cleaned_data['username']
user = Account.objects.create_user(user_id=custom_user_id,first_name=first_name,last_name=last_name,email=email,username=username,password=password)#this method is present in models.py file
user.save()
"""
User activation mail
"""
current_site = get_current_site(request)
mail_subject = "Please activate your fundaMental account"
message = render_to_string('account_verification_email.html',{
'user':user,
'domain':current_site,
'uid':urlsafe_base64_encode(force_bytes(user.pk)),
'token':default_token_generator.make_token(user),
})
to_email = email
send_email = EmailMessage(mail_subject,message,[to_email])
send_email.send()
Предполагается, что он перенаправляется на '127.0.0.1:8000/account/login/?command=verification&email=+email', но вместо этого он перенаправляется на '127.0.0.1:8000/account/signup/account/login/?command=verification&email=+email'
return redirect('account/login/?command=verification&email='+email)
else:
form = RegistrationForm()
context = {
'form':form,
}
return render(
request,"signup.html",context)
Вот мой файл urls.py
from django.urls import path
from . import views
urlpatterns = [
path('signup/',views.signup,name='signup'),
path('login/',views.login,name='login'),
path('logout/',views.logout,name='logout'),
path('activate/<uidb64>/<token>',views.activate,name='activate'),
]
Вот уровень моего проекта urls.py
from django.contrib import admin
from django.urls import path, include
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.home,name='home'),
path('account/',include('account.urls')),
]
Попробуйте с этим
redirect('home', 'account/login/?command=verification&email='+email)
Вы перенаправляете на относительную ссылку, поэтому URL ссылки перенаправления добавляется к существующему URL 'account/signup'. Чтобы сделать ссылку абсолютной, нужно добавить прямую косую черту:
return redirect('/account/login/?command=verification&email='+email)