I am a newbie for Python and Django and I have to create a web app. It is believed that after a user logs it is taken to the second page where he chooses a project to work. The problem is that when I select a project that receives "invalid login credentials" error from a log view, then successfully after logging in. I thought we were the last ... here is the idea file:
DIF login (request): reference = RequestContext (request) if request.method == 'POST': username = request .POST.get ('username') password = request.POST.get ('password') user = auth.authenticate (user name = username, password = password) if user: user.is_active: auth.login (request, User): Return render_to_response ('projectlogging / main.html', '' user ': user,' project_list ': project.objects.all ()}, context) Other: Return HttpResponse ("Your account is disabled.") And: Return (Request, User): Reference = RequestCo Ntext (request) auth.logout (request, user) Returns render_to_response ('project logging / login.html', references) @ reddit_required def logout (request, user) ProjectLogging / login.html ', {' users': none} , Context) = login_requiredef main (request, user): project: change = change (user = user, project = project, initial = datetime.datetime) if project: 'project'] reference = requestContext (request) user = user: Anu Th = request '=' 'POST': project = request Now ()) change.save () Other: HTTPRPS section ("Choose a valid project!") And: HTTPRPSPayment ("Select a post method (???????)") < P> This is the URL of the project: urlpatterns = pattern ('', url (r '', 'views.login'), url (r '^ login / $', 'Views .login '), url (r' ^ logout / $ ',' views.logout '), url (r' ^ main / $ ',' views.main '), )
In addition to this, I have not mastered how the visual, URL and HTML files are supported in the DEGENGO, so if you want to study it New site may suggest that I would be grateful. Finally, logout is not working, if you have any idea that I am even more grateful. Thank you.
URL patterns use regular expressions and first matches come back. In regular expression, a ^ is the beginning of a string, and if there is an $ end, the pattern can be found anywhere in the string and it There will still be matches. Now take a look at your first pattern.
url (r '', 'views.login'), This pattern can match the string anywhere, and it matches if The string is in "an empty string", i.e. every is a string that you can think all requests will be seen in your views.login .
To fix this, you should use the r '^ $' pattern. It will match the beginning and end of the URL path with nothing in between, i.e. only www.example.com / (the first slash is always cut). You can then access your other views on / logout / and / main / .
No comments:
Post a Comment