Where is a good place to work on accounts/profile in Django with the Django registration app? Where is a good place to work on accounts/profile in Django with the Django registration app? django django

Where is a good place to work on accounts/profile in Django with the Django registration app?


Why does after logging in, it redirects to accounts/profile/? Is there a way to change that? Preferably after successfully logging in I would like Django to redirect back to the page before the login page.

Just change setting LOGIN_REDIRECT_URL

If I were to create my own view and template for accounts/profile/, then where should I put it? Django's built-in users (auth_user) is shared among all Django apps inside a project, so should I place the view.py in the project folder and not inside the app folder?

I like to create an app called "project_specific" in every project. That's where I put all the stuff that's not meant to be reusable and that couples many apps.

You can also create a views.py at the project level, but that is sort of messy compared to making a project specific app.

In reality it does not matter where you put it.

Or does Django profile actually takes care of this whole account/profiles/ thing? I already extended Django's User class with my own UserProfile, but it's more like additional fields to the User table than an actual "profile" (I didn't create avatars or anything like that, just simple stuff like addresses and phone numbers, but most importantly, some custom user types that my app depends on).

That's not the way to add extra user fields. I recommend that you read the docs on Storing additional information about users.


For a minimal approach that doesn't require a standalone app,

  1. Create a template and call it profile.html or anything you want.

    <p>This is your profile, {{ user.username }}.</p>
  2. In urls.py, add a url pattern that points to your profile template, mark it login_required, and give the url a name:

    # ...from django.views.generic import TemplateViewfrom django.contrib.auth.decorators import login_requiredurlpatterns = [    # ...    url(r'^accounts/profile/$', TemplateView.as_view(template_name='profile.html'), name='user_profile'),    # ...]
  3. In settings.py, add the following line:

    LOGIN_REDIRECT_URL = 'user_profile'

This line tells Django to perform a reverse URL lookup by name when redirecting a user after a login. Without this line, your app will still work but it will be fragile because it relies on an arbitrary hard-coded URL that is implicitly configured by Django. With this line, if you or someone else decides that user profiles should be at /me/, you could change the URL in step 2 without breaking your app.


  1. Set LOGIN_REDIRECT_URL in settings - https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url
  2. Create account app, where contains code for this.

You may use django userena for full-stack user area: https://django-userena.readthedocs.org/en/latest/