1π
You should use some user authentication within one App which you have created, or create one App just for managing accounts.
Since you are a beginner you should take a look at Django-admin user authentication.
0π
Your question is not clear as to what you want to place. Is the template files you want to place in or the view function βlogoutβ and βloginβ? I assume it has to be the βloginβ and βlogoutβ function what you are looking for.
You have to create a views.py
file under β[projectname]/appsβ folder.
view for login
def login_validate(request): if request.method == "POST": username = request.POST['username'] password = request.POST['password'] user = authenticate(username= username, password= password) if user is not None: login(request,user) return HttpResponseRedirect('/--template name--/') else: return HttpResponseRedirect('/--template name--/') else: return HttpResponseRedirect('/--template name--/')
view for logout
def logout_page(request): logout(request) return render(request,"logout_page.html",{})Above are the functions. You will have to add few things in
settings.py
before doing this.And also create a
urls.py
file under apps folder and link it to mainurls.py
file.I hope this is clear.
https://docs.djangoproject.com/en/1.10/topics/auth/default/
https://www.youtube.com/watch?v=eMGtdtNR4es
The above links are helpful.
0π
The answer to the question is quite subjective i.e. varies from project to project, or developer to developer. My suggestions βd be:
-
As you have asked for the log-in and log-out functions, this means youβll be handling users for your app β so a good approach βd be to have a
users
app, and place the functions inusers/views.py
-
For complex system β where you may have different types of users i.e. users, admin_users, partners, etc. You can have separate directory at project root e.g.
lib/
and havefunctions.py
in it, keep all the project wide usable functions, utilities in this file.projectname]/ <- project root βββ [projectname]/ <- Django root β βββ __init__.py β βββ settings/ β βββ urls.py β βββ wsgi.py βββ myapp/ β ββ __init__.py β βββ view.py β βββ lib/ β ββ __init__.py β βββ functions.py β βββ manage.py β βββ static/ β βββ GLOBAL STATIC FILES βββ templates/ βββ GLOBAL TEMPLATES
- How can I tell if a django RelatedManager .add() found that the object was already added?
- Passing csrf token through $.ajax() data not working
- Using nested Django transaction.atomic() to handle exceptions?