Code Monkey home page Code Monkey logo

django-accounts-example-app's Introduction

Django Accounts Example

Read the accompanying article

This is an example app module that can be used in a Django project to handle authentication and account creation for users. It contains a custom user model and a profile model which can be customized depending on your project's needs.

I created this with students in mind but more advanced developers may find handy code snippets. It could also work as a hackathon starter.

Requirements

  1. A new (or new-ish) project
  2. Empty database (no existing users)
  3. Python 3

What it does

This app only adds 3 routes: login, logout, and signup. Any other urls should return a 404 (unless handled by other apps).

That's it! That's all it does.

Steps

Start by copying this app folder into the project root. To create a new project from scratch try:

$ django-admin startproject

(will either need to have django installed globally or be in an active virtualenv with django installed)

Next, rename the folder from 'django-accounts-example-app' to just 'accounts'.

Side note: I would recommend deleting the .git folder above messing around with submodules. This project is meant to be a baseline to build your own thing off of, not a package.

in settings.py

Add 'accounts' to INSTALLED_APPS:

INSTALLED_APPS = [
    'django.contrib.admin',
    ...
    'accounts',
]

So Django uses the custom user model instead of the default one:

AUTH_USER_MODEL = 'accounts.User'

in urls.py (main app)

Add this to your main url dispatcher (the urls.py in your project's main app):

from django.urls import include, path

urlpatterns = [
    path('accounts/', include('accounts.urls')),
]

in terminal

Run:

$ python manage.py makemigrations accounts && python manage.py migrate

This command will not work (and probably break things) if you already have users in your database.

in other apps

To use the custom user model in other apps:

from django.contrib.auth import get_user_model
User = get_user_model()

django-accounts-example-app's People

Contributors

jasminedevv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.