python - Django redirect to root from a view -


I am making a project in the project. However, I have come across a small hiccup. My urls.py looks like this

  url (r '^ login / (? P  
  DIF login (request, NextLoc): if request.method == "POST ": Form = AuthenticationForm (request.POST) user = auth.authenticate (user name = request.POST ['username'], password = request.POST ['password']) If there is no user: if user.is_active: Auth.login (request, user) Redirect redirect (nextLoc) Other: Error = 'This Account Individual Please contact the administrator to enable that account disabled by the administrator 'else: error =' Username / password pair is wrong I check your credentials and try again. 'Other: If request.user.is_authenticated (): Return redirect ("/ profile /") form = authentication form () error = '' return render_to_response ('login.html', {'FORM': form, 'ERROR': error}, Context_instance = RequestContext (request) ) Def logout (request): auth.logout (request) returns redirection (' / ')   

Now when I'm going to the login page, opening in the expected form. After submitting the form, I get an error that says it has the module URL After finding a little excavation, I have found that the redirect ("/") is actually http: // localhost / instead of http: // localhost / login / Translated into . This is the case with logout, i.e. it tries to open the URL http: // localhost / logout / instead of http: // localhost / . Basically, when the page is opened is http: // localhost / login , then redirect ('/') adds the / wola at the end of the current URL, and Vola - I get the URL I did not expect - http: // localhost / login / .

Please help me with this and if possible please explain the reasons for this irrational behavior of the DJ

If you look at, there are several things that you can pass the function:

  • One model
  • One URL < / Li>
  • One URL

    In general, I think it is better to redirect to a view name instead of a URL. In your case, assuming there is an entry in your urls.py that looks like this:

      url (r '^ $', 'home.views.index'), < / Code>  

    I would rather use redirect like this:

      Redirect ('Home Visits Index')    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -