django allauth login & signup form on homepage

后端 未结 2 1083
甜味超标
甜味超标 2020-12-17 04:44

I have been looking for a solution for some time now and I am not able to wrap my head around this. All I am trying to accomplish is to have the allauth login and signup for

2条回答
  •  萌比男神i
    2020-12-17 05:06

    these steps worked for me 1. goto allauth\account\views
    In the loginView class under get_context_data function add the the following code signup_form context rendering to the ret

    ret.update({"signup_url": signup_url,
                    "site": site,                   
                    "redirect_field_name": self.redirect_field_name,
                    "redirect_field_value": redirect_field_value,
                    -->"signup_form":get_form_class(app_settings.FORMS, 'signup',SignupForm)<--
    })return ret
    
    1. in your app views.py

      def homepage(request):
          template = 'account/login.html'
          context ={}
          return render(request, template, context)
      
    2. your urls.py

      from .views import homepage

      path('', homepage, name='home'),

    3. in your account/login.html

      {% include "account/signup.html" with form=signup_form %}

    see https://github.com/believeohiozua/django-allauth/blob/master/allauth/account/views.py for sample code

    if you are okay with the above repository you can just install with
    pip install git+https://github.com/believeohiozua/django-allauth.git

提交回复
热议问题