1

I have created a Django App and want to provide a custom Login page with only the possibility to use a Google login.

I have implemented the Google login based on this post: https://www.section.io/engineering-education/django-google-oauth/ It actually works fine and when I hit localhost/account/login I am getting a login page: Django standard login screen

I actually do not want a sign up and a "local" sign in option, I only need a Google login.

To achieve this I have created the following folder structure to overwrite the login template (based on https://learndjango.com/tutorials/django-login-and-logout-tutorial): MyApp/templaltes/registration/login.html

Folder structure

login.html has the following content:

{% extends "base.html" %}
{% load i18n %}
{% load socialaccount %}
{% block content %}
    <div class="row">
        <center><h1>{% trans 'LoginHeading' %}</h1></center>
    </div>
    {% if user.is_authenticated %}
        <p>Welcome, You are logged in as {{ user.username }}</p>
    {% else %}
        <a href="{% provider_login_url 'google' %}">Login With Google</a>
    {% endif %}
{% endblock %}

I have also added 'DIRS': [str(BASE_DIR.joinpath('templates'))] to the TEMPLATES section in settings.py.

Unfortunately I am still seeing the Django default login page. What am I missing?

(I have also restarted the dev server to make sure it is not an issue there with the same result)

TerenceJackson
  • 1,776
  • 15
  • 24

3 Answers3

1

I have figured it out. After reading the documentation of Allauth throughly I found this:

For instance, the view corresponding to the account_login URL uses the template account/login.html. If you create a file with this name in your code layout, it can override the one shipped with allauth.

So I changed the folder structure to account/login.html and it works.

TerenceJackson
  • 1,776
  • 15
  • 24
1

To do this thing you can simply create an account folder under the template and add login.html inside it. This will override your login page. Make sure that folder name must be account.

In your case, you can rename your folder from "registration" to "account". Like following: enter image description here

I am sure this will work well.

1

Simple solution is to add

SOCIALACCOUNT_LOGIN_ON_GET=True

to your settings.py and it should skip/bypass the sign up form.

Credits: https://stackoverflow.com/a/70680165/11605100


Still does not work?

Stop the server and then;

python manage.py migrate
python manage.py makemigrations
python manage.py runserver
ajinzrathod
  • 925
  • 10
  • 28