Use these views and templates to interact with the django.contrib.auth.models.User
model. Allow your end users to easily login, logout, register, and manage their profile.
These views and templates are designed to be bear bones, not a lot of bells and whistles here.
Don't get bogged down managing Users, focus on writing your application!
-
Install django-simple-accounts from GitHub using pip:
pip install git+ssh://[email protected]/atheiman/django-simple-accounts.git@master
-
Add the Django app
accounts
toINSTALLED_APPS
in your settings file:# settings.py INSTALLED_APPS = ( # ... 'accounts', )
-
Include the django-simple-accounts urls in your
ROOT_URLCONF
:# urls.py urlpatterns = patterns('', # ... url(r'^accounts/', include('accounts.urls', namespace='accounts')), )
-
Create your UserProfile model if desired:
# models.py class UserProfile(models.Model): user = models.OneToOneField(User) phone = models.CharField( max_length=12, blank=True, ) # more model fields as needed def __unicode__(self): return self.user.username
-
Configure django-simple-accounts in your settings:
# settings.py DJANGO_SIMPLE_ACCOUNTS = { # python 'USER_PROFILE_PYTHON_PATH': 'my_app.models.UserProfile', }
Configuration is described completely below.
-
Run the app and check it out:
$ python manage.py makemigrations $ python manage.py migrate $ python manage.py runserver
You should see Profiles as a StackedInline included in your admin site at /admin/auth/user/.
The following URLs / views are also implemented for use:
Configuration for django-simple-accounts is set in the django.settings.DJANGO_SIMPLE_ACCOUNTS
dict. None of the keys are required to be set, however you must at least define the dict with no keys (DJANGO_SIMPLE_ACCOUNTS = {}
).
Example configuration dict with all keys set:
# settings.py
DJANGO_SIMPLE_ACCOUNTS = {
'USER_PROFILE_PYTHON_PATH': 'my_app.models.UserProfile',
}
An explanation of each key availble to be set is described below:
Dotted python path to a subclass of django.db.models.Model
that you have defined as a User Profile model as described in the Django docs. This setting allows:
- an instance of the UserProfile model is created when a new User is created
- the profile view includes fields for the UserProfile model
- Be sure to set Field.default or Field.blank and Field.null for all of your UserProfile model fields, because when the UserProfile instance is first created no fields will be set. Those fields are set from the profile view (after registration).
As recommended above, it generally makes sense to include accounts.urls
at `/accounts/. If you are going to place these at a different location, be sure to change the LOGIN_REDIRECT_URL, LOGIN_URL, and LOGOUT_URL described here.
[ ] User Profile Model management
[ ] Login with Google or Facebook
[ ] Register
[ ] Email registration confirmation link
[x] Configure with django settings