---
slug: "django-allauth-return-redirect-view-without-specifying-social-account"
title: "Return Login and Redirect Views by Hardcoding Social Account Provider in django-allauth (When Using AWS Cognito, etc.)"
description: "How to Create a Login View in Django Allauth Without Specifying the Social Account Backend in the URL"
url: "https://www.ytyng.com/en/blog/django-allauth-return-redirect-view-without-specifying-social-account"
publish_date: "2024-12-14T04:46:02Z"
created: "2024-12-14T04:46:02Z"
updated: "2026-02-27T07:11:15.534Z"
categories: ["Django"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250609/e19643bb3de64156a31b3b66df4b80cf.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/315/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/315/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/315/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/315/featured-music-315-2.mp3", "https://media.ytyng.net/ytyng-blog/315/featured-music-315-3.mp3"]
lang: "en"
---

# Return Login and Redirect Views by Hardcoding Social Account Provider in django-allauth (When Using AWS Cognito, etc.)

How to Create a Login View in Django Allauth Without Specifying the Social Account Backend in the URL

This can be useful if you're using only one backend like AWS Cognito.

# Login View

To display a login button:

```python
from allauth.socialaccount.providers.amazon_cognito.views import oauth2_login

async def login_view(request):
    return oauth2_login(request)
```

# View to Redirect to the Login URL

To redirect to the managed login URL of Cognito:

### Settings
```python
SOCIALACCOUNT_LOGIN_ON_GET = True
```

```python
from allauth.socialaccount.providers.amazon_cognito.views import oauth2_login

async def login_view(request):
    return oauth2_login(request)
```

Alternatively:

```python
from allauth.socialaccount.providers.amazon_cognito.views import oauth2_login, AmazonCognitoOAuth2Adapter

def login_redirect_view(request):
    adapter = AmazonCognitoOAuth2Adapter(request)
    provider = adapter.get_provider()
    return provider.redirect_from_request(request)
```

# Other Recommended Settings for Allauth

### Settings

```python
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = 'https://<your-cognito-managed-url>/logout?client_id=<cognito-client-id>>&logout_uri=https%3A%2F%2F<your-webapp>'  # NOQA
ACCOUNT_EMAIL_VERIFICATION = 'none'
SOCIALACCOUNT_ONLY = True
```
