url - How to show different view for logged user in Django? -


Assume that I have followed the ScheduleList views where users (logged in or not) work The list can be viewed on selected days and PersonalizedScheduleList where the user can see all the tasks (he must log in). I could use a ListView and put the get_queryset method bigger, if not authenticated for the user - the data process is different

Log in and not logged in How to show different views on a single URL pattern for the user made, logged in users can view their schedule list on the main page and can not log in. Can you see the work by selecting the day?

  urlpattern ('', url (r '^ $', views.ScheduleList.as_view ()), # user url (r '^ $', views.PersonalizedScheduleList.as_view ()) , # Log in user) About  

Regarding the handling of the request handling and the url Need to think the way. A request has been received, Django finds the first URL pattern that matches the URL of the request and that category (or in your case, with a __ call __ defined method (CBV implementation details) To the specified work call. This means that, at the URL-routing level, the header values ​​(authentication usually based on some headers, cookie, etc.) are based on one view on one location Unless the URL is different.

Solution

  1. Write a type of interceptor view based on the login status of the incoming request, which Allows to show the view (this is only a view whose receipt / post methods come back) The result of calling one of the two views outlined in your question)
  2. To send the user to the correct view, The app's workflow Design, keep each view on a different URL path (this is cleaner handling things) - Your in-page JavaScript can handle this client-side, while backend is the use of accidental (or malicious) mis-visual efforts

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -