मैं एक django परियोजना बना रहा हूँ। हालांकि, मैं एक छोटे से हिचकी भर में आया है। मेरे urls.py लग रहा है इसDjango एक दृश्य से रूट करने के लिए रीडायरेक्ट
url(r'^login/(?P<nextLoc>)$', 'Home.views.login'),
url(r'^logout/$', 'Home.views.logout'),
होम ऐप्लिकेशन में मेरी views.py की तरह इस प्रकार है:
def login(request,nextLoc):
if request.method == "POST":
form = AuthenticationForm(request.POST)
user=auth.authenticate(username=request.POST['username'],password=request.POST['password'])
if user is not None:
if user.is_active:
auth.login(request, user)
return redirect(nextLoc)
else:
error='This account has been disabled by the administrator. Contact the administrator for enabling the said account'
else:
error='The username/password pair is incorrect. Check your credentials and try again.'
else:
if request.user.is_authenticated():
return redirect("/profile/")
form = AuthenticationForm()
error=''
return render_to_response('login.html',{'FORM':form,'ERROR':error},context_instance=RequestContext(request))
def logout(request):
auth.logout(request)
return redirect('/')
अब जब मैं प्रवेश पृष्ठ पर जा रहा हूँ, यह खुल रहा है के रूप में उम्मीद। फॉर्म जमा करने के बाद, मुझे एक त्रुटि मिलती है जो कहती है कि यह मॉड्यूल यूआरएल नहीं ढूंढ सकता है। थोड़ा सा खोदने के बाद, मैंने देखा कि रीडायरेक्ट ("/") वास्तव में http://localhost/
के बजाय http://localhost/login/
में अनुवाद करता है। लॉगआउट में भी ऐसा ही होता है, यानी यह http://localhost/
के बजाय यूआरएल http://localhost/logout/
खोलने का प्रयास करता है। असल में, जब पृष्ठ खोला जाता है http://localhost/login
है, तो redirect('/')
वर्तमान यूआरएल के अंत में/जोड़ता है - मुझे एक यूआरएल मिलता है जिसकी मुझे उम्मीद नहीं थी - http://localhost/login/
। मैं इसे रीडायरेक्ट का उपयोग कर साइट की जड़ पर रीडायरेक्ट करने के लिए नहीं मिल सकता।
कृपया मुझे इस के साथ मदद कर बाहर और यदि संभव हो तो भी Django के इस तर्कहीन व्यवहार के कारण की व्याख्या
आप HttpResponseRedirect की कोशिश की? django.http आयात से HttpResponseRedirect डीईएफ़ लॉगआउट (अनुरोध): \t वापसी HttpResponseRedirect ("/") –
जहाँ आपके urls.py के बाकी है? क्या विचार "/" से मेल खाता है? – jterrace