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
xsendfile etc wrapper

Django Sendfile This is a wrapper around web-server specific methods for sending files to web clients. This is useful when Django needs to check permi

John Montgomery 476 Dec 01, 2022
Django Phyton Web Apps template themes

Django Phyton Web Apps template themes Free download source code project for build a modern website using django phyton web apps. Documentation instal

Mesin Kasir 4 Dec 15, 2022
An API was build with Django to store and retrieve information about various musical instruments.

The project is meant to be a starting point, an experimentation or a basic example of a way to develop an API with Django. It is an exercise on using Django and various python technologies and design

Kostas Ziovas 2 Dec 25, 2021
A simple trivia quizzz web app made using django

Trivia Quizzz A simple trivia quizzz web app made using django Demo http://triviaquizzz.herokuapp.com/ & https://triviaquiz.redcrypt.xyz Features Goog

Rachit Khurana 2 Feb 10, 2022
Comparing Database performance with Django ORM

Comparing Database performance with Django ORM Postgresql MySQL MariaDB SQLite Comparing database operation performance using django ORM. PostgreSQL v

Sarath ak 21 Nov 14, 2022
Django Email Sender

Email-Sender Django Email Sender Installation 1.clone Repository & Install Packages git clone https://github.com/telman03/Email-Sender.git pip install

Telman Gadimov 0 Dec 26, 2021
Projeto onde podes inserir notícias, ver todas as notícias guardas e filtrar por tag. A base de dados usada é o mongoDB.

djangoProject Projeto onde podes inserir notícias, ver todas as notícias guardas e filtrar por tag. A base de dados usada é o mongoDB. packages utiliz

Sofia Rocha 1 Feb 22, 2022
Store events and publish to Kafka

Create an event from Django ORM object model, store the event into the database and also publish it into Kafka cluster.

Diag 6 Nov 30, 2022
Forward and backwards compatibility layer for Django 1.4, 1.7, 1.8, 1.9, 1.10, and 1.11

django-compat Forward and backwards compatibility layer for Django 1.4 , 1.7 , 1.8, 1.9, 1.10 and 1.11 Consider django-compat as an experiment based o

arteria GmbH 106 Mar 28, 2022
Simply integrate Summernote editor with Django project.

django-summernote Summernote is a simple WYSIWYG editor. django-summernote allows you to embed Summernote into Django very handy. Support admin mixins

Summernote 936 Jan 02, 2023
Django GUID attaches a unique correlation ID/request ID to all your log outputs for every request.

Django GUID Now with ASGI support! Django GUID attaches a unique correlation ID/request ID to all your log outputs for every request. In other words,

snok 300 Dec 29, 2022
Official Python agent for the Elastic APM

elastic-apm -- Elastic APM agent for Python This is the official Python module for Elastic APM. It provides full out-of-the-box support for many of th

elastic 369 Jan 05, 2023
Simple application TodoList django with ReactJS

Django & React Django We basically follow the Django REST framework quickstart guide here. Create backend folder with a virtual Python environment: mk

Flavien HUGS 2 Aug 07, 2022
Repo for All the Assignments I have to submit for Internship Application !😅

Challenges Repository for All the Assignments I have to submit for Internship Application ! 😅 As You know, When ever We apply for an Internship, They

keshav Sharma 1 Sep 08, 2022
A small Django app to easily broadcast an announcement across a website.

django-site-broadcasts The site broadcast application allows users to define short messages and announcements that should be displayed across a site.

Ben Lopatin 12 Jan 21, 2020
Django based webapp pulling in crypto news and price data via api

Deploy Django in Production FTA project implementing containerization of Django Web Framework into Docker to be placed into Azure Container Services a

0 Sep 21, 2022
Auto-detecting the n+1 queries problem in Python

nplusone nplusone is a library for detecting the n+1 queries problem in Python ORMs, including SQLAlchemy, Peewee, and the Django ORM. The Problem Man

Joshua Carp 837 Dec 29, 2022
A django model and form field for normalised phone numbers using python-phonenumbers

django-phonenumber-field A Django library which interfaces with python-phonenumbers to validate, pretty print and convert phone numbers. python-phonen

Stefan Foulis 1.3k Dec 31, 2022
A Redis cache backend for django

Redis Django Cache Backend A Redis cache backend for Django Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/. Changelog 3.0.0

Sean Bleier 1k Dec 15, 2022
Loguru is an exceeding easy way to do logging in Python

Django Easy Logging Easy Django logging with Loguru Loguru is an exceeding easy way to do logging in Python. django-easy-logging makes it exceedingly

Neutron Sync 8 Oct 17, 2022