A Django app that allows visitors to interact with your site as a guest user without requiring registration.

Overview

django-guest-user

A Django app that allows visitors to interact with your site as a guest user without requiring registration.

Largely inspired by django-lazysignup and rewritten for Django 3 and Python 3.6 and up.

Installation

Install the package with your favorite package manager from PyPI:

pip install django-guest-user

Add the app to your INSTALLED_APPS and AUTHENTICATION_BACKENDS:

INSTALLED_APPS = [
    ...
    "django_guest_user",
]

AUTHENTICATION_BACKENDS = [
    "django.contrib.auth.backends.ModelBackend",
    "guest_user.backends.GuestBackend",
]

Add the patterns to your URL config:

urlpatterns = [
    ...
    path("convert/", include("guest_user.urls")),
]

Don't forget to run migrations:

python manage.py migrate

How to use

Guest users are not created for every unauthenticated request. Instead, use the @allow_guest_user decorator on a view to enable that view to be accessed by a temporary guest user.

from guest_user.decorators import allow_guest_user

@allow_guest_user
def my_view(request):
    # Will always be either a registered a guest user.
    username = request.user.username
    return HttpResponse(f"Hello, {username}!")

API

@guest_user.decorators.allow_guest_user

View decorator that will create a temporary guest user in the event that the decorated view is accessed by an unauthenticated visitor.

Takes no arguments.

@guest_user.decorators.guest_user_required(redirect_field_name="next", login_url=None)

View decorator that redirects to a given URL if the accessing user is anonymous or already authenticated.

Arguments:

  • redirect_field_name: URL query parameter to use to link back in the case of a redirect to the login url. Defaults to django.contrib.auth.REDIRECT_FIELD_NAME ("next").
  • login_url: URL to redirect to if the user is not authenticated. Defaults to the LOGIN_URL setting.

@guest_user.decorators.regular_user_required(redirect_field_name="next", login_url=None)

Decorator that will not allow guest users to access the view. Will redirect to the conversion page to allow a guest user to fully register.

Arguments:

  • redirect_field_name: URL query parameter to use to link back in the case of a redirect to the login url. Defaults to django.contrib.auth.REDIRECT_FIELD_NAME ("next").
  • login_url: URL to redirect to if the user is a guest. Defaults to "guest_user_convert".

guest_user.functions.get_guest_model()

The guest user model is swappable. This function will return the currently configured model class.

guest_user.functions.is_guest_user(user)

Check wether the given user instance is a temporary guest.

guest_user.signals.converted

Signal that is dispatched when a guest user is converted to a regular user.

Template tag is_guest_user

A filter to use in templates to check if the user object is a guest.

{% load guest_user %}

{% if user|is_guest_user %}
  Hello guest.
{% endif %}

Settings

Various settings are provided to allow customization of the guest user behavior.

GUEST_USER_ENABLED

bool. If False, the @allow_guest_user decorator will not create guest users. Defaults to True.

GUEST_USER_MODEL

str. The swappable model identifier to use as the guest model. Defaults to "guest_user.Guest".

GUEST_USER_NAME_GENERATOR

str. Import path to a function that will generate a username for a guest user. Defaults to "guest_user.functions.generate_uuid_username".

Included with the package are two alternatives:

"guest_user.functions.generate_numbered_username": Will create a random four digit number prefixed by GUEST_USER_NAME_PREFIX.

"guest_user.functions.generate_friendly_username": Creates a friendly and easy to remember username by combining an adjective, noun and number. Requires random_username to be installed.

GUEST_USER_NAME_PREFIX

str. A prefix to use with the generate_numbered_username generator. Defaults to "Guest".

GUEST_USER_CONVERT_FORM

str. Import path for the guest conversion form. Must implement get_credentials to be passed to Django's authenticate function. Defaults to "guest_user.forms.UserCreationForm".

GUEST_USER_CONVERT_PREFILL_USERNAME

bool. Set the generated username as initial value on the conversion form. Defaults to False.

GUEST_USER_CONVERT_URL

str. URL name for the convert view. Defaults to "guest_user_convert".

GUEST_USER_CONVERT_REDIRECT_URL

str. URL name to redirect to after conversion, unless a redirect parameter was provided. Defaults to "guest_user_convert_success".

GUEST_USER_BLOCKED_USER_AGENTS

list[str]. Web crawlers and other user agents to block from becoming guest users. The list will be combined into a regular expression. Default includes a number of well known bots and spiders.

Status

This project is currently untested. But thanks to previous work it is largely functional.

I decided to rewrite the project since the original project hasn't seen any larger updates for a few years now and the code base was written a long time ago.

You might also like...
 An insecure login and registration website with Django.
An insecure login and registration website with Django.

An insecure login and registration website with Django.

Vehicle registration using Python, Django and SQlite3

PythonCrud Cadastro de veículos utilizando Python, Django e SQlite3 Para acessar o deploy no Heroku:

A handy tool for generating Django-based backend projects without coding. On the other hand, it is a code generator of the Django framework.
A handy tool for generating Django-based backend projects without coding. On the other hand, it is a code generator of the Django framework.

Django Sage Painless The django-sage-painless is a valuable package based on Django Web Framework & Django Rest Framework for high-level and rapid web

Django API without Django REST framework.

Django API without DRF This is a API project made with Django, and without Django REST framework. This project was done with: Python 3.9.8 Django 3.2.

django-idom allows Django to integrate with IDOM

django-idom allows Django to integrate with IDOM, a package inspired by ReactJS for creating responsive web interfaces in pure Python.

Displaying objects on maps in the Django views and administration site.
Displaying objects on maps in the Django views and administration site.

DjangoAdminGeomap library The free, open-source DjangoAdminGeomap library is designed to display objects on the map in the Django views and admin site

Use webpack to generate your static bundles without django's staticfiles or opaque wrappers.

django-webpack-loader Use webpack to generate your static bundles without django's staticfiles or opaque wrappers. Django webpack loader consumes the

A Django web application that allows you to be in the loop about everything happening in your neighborhood.
A Django web application that allows you to be in the loop about everything happening in your neighborhood.

A Django web application that allows you to be in the loop about everything happening in your neighborhood. From contact information of different handyman to meeting announcements or even alerts.

Django project starter on steroids: quickly create a Django app AND generate source code for data models + REST/GraphQL APIs (the generated code is auto-linted and has 100% test coverage).

Create Django App 💛 We're a Django project starter on steroids! One-line command to create a Django app with all the dependencies auto-installed AND

Comments
  • Add django-tos contrib app

    Add django-tos contrib app

    This PR adds an integration with django-tos.

    It is necessary when using django-tos's middleware option (2). When using django-tos' middleware, since guest users have full user accounts they are required to agree to the site's terms of service before they can do anything else.

    I have refactored django-tos a bit in revsys/django-tos#65 specifically to make this custom middleware easier to write. That PR allows us to minimize the amount of code necessary in this middleware and any changes to upstream django-tos should not interfere with this middleware.

    opened by blag 3
  • RFC on a changing GuestManager.convert to update in-place

    RFC on a changing GuestManager.convert to update in-place

    Hi @julianwachholz,

    First off, thank you very much for maintaining this package for new versions of Django!

    I've opened this ticket to propose a relatively simple change (or addition) of the GuestManager in the package that I think would enable greater functionality for devs wanting to create guest users.

    Background

    Business Use Case

    I started using this package to enable guest users functionality on a site, with the goal that:

    • ephemeral guest users would be able to modify the db (ie CRUD their own objects like a regular user)
    • after conversion all of the state in related models would be maintained

    After reading the documentation for django-guest-user I didn't see any flags that stated this usage wasn't possible, but after installing the package and trying to use it, to the best of my understanding, the use case above is not supported. I think this has also been raised previously in https://github.com/julianwachholz/django-guest-user/issues/3.

    EDIT:

    • This use case is supported; I had a misconfigured form and had misread the guest creation workflow when debugging.

    Thanks very much for your time!

    opened by mbhynes 3
  • How to log in instead of registering a new user?

    How to log in instead of registering a new user?

    Hi @julianwachholz,

    Thanks a lot for working on this package, it's very useful!

    I had a question I hoped you could help me answer: Is there a way to allow the user to log in, instead of creating a new user during the conversion? So that if a user hadn't logged in before putting items in the cart, he can still keep them

    Thank you.

    Best, Dylan

    opened by dylanjcastillo 2
  • Django 4.0

    Django 4.0

    This PR:

    • removes one last feature that was deprecated in Django 4.0 (which silences a warning from this package when running tests)
    • adds Django 4.0 to the test matrix
    • removes Django 3.1 from the test matrix (since this is EOL in just a few days)
    • adds Python 3.10 to the test matrix
    opened by blag 1
Releases(0.5.3)
Owner
Julian Wachholz
Python and JavaScript developer. I enjoy riding motorcycles and playing board games. PGP: https://julianwachholz.dev/julian_wachholz_pub.asc
Julian Wachholz
A slick ORM cache with automatic granular event-driven invalidation.

Cacheops A slick app that supports automatic or manual queryset caching and automatic granular event-driven invalidation. It uses redis as backend for

Alexander Schepanovski 1.7k Jan 03, 2023
Comprehensive Markdown plugin built for Django

Django MarkdownX Django MarkdownX is a comprehensive Markdown plugin built for Django, the renowned high-level Python web framework, with flexibility,

neutronX 738 Dec 21, 2022
✋ Auto logout a user after specific time in Django

django-auto-logout Auto logout a user after specific time in Django. Works with Python 🐍 ≥ 3.7, Django 🌐 ≥ 3.0. ✔️ Installation pip install django-a

Georgy Bazhukov 21 Dec 26, 2022
pytest-django allows you to test your Django project/applications with the pytest testing tool.

pytest-django allows you to test your Django project/applications with the pytest testing tool.

pytest-dev 1.1k Dec 14, 2022
Django Rest Framework + React application.

Django Rest Framework + React application.

2 Dec 19, 2022
Django Course Project - TextCorrector

Django-TextUtils Django Course Project A tool for analyzing text data in Django backend. It is a project where you can do some of the things with you

1 Oct 29, 2021
Django application and library for importing and exporting data with admin integration.

django-import-export django-import-export is a Django application and library for importing and exporting data with included admin integration. Featur

2.6k Dec 26, 2022
Yet another Django audit log app, hopefully the simplest one.

django-easy-audit Yet another Django audit log app, hopefully the easiest one. This app allows you to keep track of every action taken by your users.

Natán 510 Jan 02, 2023
Django-static-site - A simple content site framework that harnesses the power of Django without the hassle

coltrane A simple content site framework that harnesses the power of Django with

Adam Hill 57 Dec 06, 2022
The friendly PIL fork (Python Imaging Library)

Pillow Python Imaging Library (Fork) Pillow is the friendly PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lund

Pillow 10.4k Jan 03, 2023
It takes time to start a Django Project and make it almost production-ready.

It takes time to start a Django Project and make it almost production-ready. A developer needs to spend a lot of time installing required libraries, setup a database, setup cache as well as hiding se

Khan Asfi Reza 1 Jan 01, 2022
Updates redisearch instance with igdb data used for kimosabe

igdb-pdt Update RediSearch with IGDB games data in the following Format: { "game_slug": { "name": "game_name", "cover": "igdb_coverart_url",

6rotoms 0 Jul 30, 2021
Flashback is an awesome, retro IRC based app built using Django

Flashback Flashback is an awesome, retro IRC based app built using Django (and the Django Rest Framework) for the backend as well as React for the fro

Unloading Gnat 1 Dec 22, 2021
English dictionary using Django based on freecodecamp

English Dictionary Hi there, i made this english dictionary using Django based on freecodecamp.org tutorial :) Table of Contents Preview Technologies

Aline Alencar 3 May 09, 2022
Full control of form rendering in the templates.

django-floppyforms Full control of form rendering in the templates. Authors: Gregor Müllegger and many many contributors Original creator: Bruno Renié

Jazzband 811 Dec 01, 2022
Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Cookiecutter Django Powered by Cookiecutter, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. Documentati

Daniel Feldroy 10k Dec 31, 2022
Django query profiler - one profiler to rule them all. Shows queries, detects N+1 and gives recommendations on how to resolve them

Django Query Profiler This is a query profiler for Django applications, for helping developers answer the question "My Django code/page/API is slow, H

Django Query Profiler 116 Dec 15, 2022
Stream Framework is a Python library, which allows you to build news feed, activity streams and notification systems using Cassandra and/or Redis. The authors of Stream-Framework also provide a cloud service for feed technology:

Stream Framework Activity Streams & Newsfeeds Stream Framework is a Python library which allows you to build activity streams & newsfeeds using Cassan

Thierry Schellenbach 4.7k Jan 02, 2023
Django React Flight Rezervation

Django Intro & Installation python -m venv venv source ./venv/Scripts/activate pip install Django pip install djangorestframework pip install python-d

HILMI SARIOGLU 2 May 26, 2022
Tweak the form field rendering in templates, not in python-level form definitions. CSS classes and HTML attributes can be altered.

django-widget-tweaks Tweak the form field rendering in templates, not in python-level form definitions. Altering CSS classes and HTML attributes is su

Jazzband 1.8k Jan 02, 2023