当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Customizing django-allauth Login view

问题描述:

I am new to django and im trying to setup a login and signup page using django allauth. I successfully managed to do use with the help of various tutorials. However I want to customize my login page but at the same time I keep using the allauth code. Using the answer to this QUESTION, I have managed to make some progress but i still can't get to displaying any form fields on my template.

Basically I'm looking for an explanation for the code to the question identified above, but one is toned down to help a beginner.

This is the code that i currently have:

My views.py

from django.shortcuts import render

from django.http import HttpResponse

from .forms import nibit_login

def login(request):

context = {

'login_form': nibit_login(),

}

return render(request, 'accounts_app/nibit_login.html', context)

My forms.py

from allauth.account.forms import LoginForm

class nibit_login(LoginForm):

def __init__(self,*args,**kwargs):

super(LoginForm, self).__init__(*args,**kwargs)

self.fields['remember'].label = 'Stay signed in'

self.fields['remember'].initial = True

nibit_login.html template

<html>

<head>

<title>Login</title>

</head>

<body>

<p> This is the login template </p>

<form method="post" class="login-form">

{% csrf_token %}

{{ context.as_p }}

<button type="submit" class="save btn btn-default">Save</button>

</form>

</body>

</html>

This is what I am looking to be helped with:

  1. To get the form fields inherited from allauth Login form to show on my template so i can customize
  2. Suggestion on how I can better customize a django-allauth Login form

网友答案:

I've just come across this question looking for advice on customising the allauth login page.

I think your problem is that you're passing the context, but using the wrong keyword to reference the context in the template.

In nibit.html, try changing {{ context.as_p }} to {{ login_form.as_p }}

分享给朋友:
您可能感兴趣的文章:
随机阅读: