Note that there are some explanatory texts on larger screens.

plurals
  1. POCustomized views with django-registration
    primarykey
    data
    text
    <p>I need to make a very simple modification -- require that certain views only show up when a user is not authenticated -- to django-registration default views. For example, if I am logged in, I don't want users to be able to visit the /register page again. </p> <p>So, I think the idea here is that I want to subclass the <code>register</code> view from django-registration. This is just where I'm not sure how to proceed. Is this the right direction? Should I test the user's authentication status here? Tips and advice welcomed!</p> <p><strong>Edit</strong></p> <p>I think this is the right track here: <a href="https://stackoverflow.com/questions/2320581/django-redirect-logged-in-users-from-login-page">Django: Redirect logged in users from login page</a></p> <p><strong>Edit 2</strong></p> <p>Solution:</p> <p>Create another app, for example, <code>custom_registration</code>, and write a view like this (mine uses a custom form as well):</p> <pre><code>from registration.views import register from custom_registration.forms import EduRegistrationForm def register_test(request, success_url=None, form_class=EduRegistrationForm, profile_callback=None, template_name='registration/registration_form.html', extra_context=None): if request.user.is_authenticated(): return HttpResponseRedirect('/') else: return register(request, success_url, form_class, profile_callback, template_name, extra_context) </code></pre> <p>I had to use the same function parameters, but otherwise just include the test, and if we pass it, continue to the main function. </p> <p>Don't forget to put this in your URLConf either (again, this includes some stuff about my custom form as well):</p> <p>top-level URLConf</p> <pre><code>(r'^accounts/', include('custom_registration.urls')), (r'^accounts/', include('registration.urls')), </code></pre> <p>custom_registration.views</p> <pre><code>from django.conf.urls.defaults import * from custom_registration.views import register_test from custom_registration.forms import EduRegistrationForm urlpatterns = patterns('', url(r'^register/$', register_test, {'form_class': EduRegistrationForm}, name='registration.views.register'), ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload