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
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
Simple Login Logout System using Django, JavaScript and ajax.

Djanog-UserAuthenticationSystem Technology Use #version Python 3.9.5 Django 3.2.7 JavaScript --- Ajax Validation --- Login and Logout Functionality, A

Bhaskar Mahor 3 Mar 26, 2022
A multiprocessing distributed task queue for Django

A multiprocessing distributed task queue for Django Features Multiprocessing worker pool Asynchronous tasks Scheduled, cron and repeated tasks Signed

Ilan Steemers 1.7k Jan 03, 2023
Neighbourhood - A python-django web app to help the residence of a given neighborhood know their surrounding better

Neighbourhood A python-django web app to help the residence of a given neighborh

Levy Omolo 4 Aug 25, 2022
An URL Shortener with Basic Features.

Simple Url Shortener What is that? Yet another url shortener built with Django framework. Preview HOW TO RUN? 1. Virtual Environment First create a vi

Ethem Turgut 6 Jan 25, 2022
Python port of Google's libphonenumber

phonenumbers Python Library This is a Python port of Google's libphonenumber library It supports Python 2.5-2.7 and Python 3.x (in the same codebase,

David Drysdale 3.1k Jan 08, 2023
Django + NextJS + Tailwind Boilerplate

django + NextJS + Tailwind Boilerplate About A Django project boilerplate/templa

Shayan Debroy 3 Mar 11, 2022
Keep track of failed login attempts in Django-powered sites.

django-axes Axes is a Django plugin for keeping track of suspicious login attempts for your Django based website and implementing simple brute-force a

Jazzband 1.1k Dec 30, 2022
PEP-484 stubs for django-rest-framework

pep484 stubs for Django REST framework Mypy stubs for DRF 3.12.x. Supports Python 3.6, 3.7, 3.8 and 3.9. Installation pip install djangorestframework-

TypedDjango 303 Dec 27, 2022
Django Persistent Filters is a Python package which provide a django middleware that take care to persist the querystring in the browser cookies.

Django Persistent Filters Django Persistent Filters is a Python package which provide a django middleware that take care to persist the querystring in

Lorenzo Prodon 2 Aug 05, 2022
Super simple bar charts for django admin list views visualizing the number of objects based on date_hierarchy using Chart.js.

Super simple bar charts for django admin list views visualizing the number of objects based on date_hierarchy using Chart.js.

foorilla LLC 4 May 18, 2022
A blog app powered by python-django

Django_BlogApp This is a blog app powered by python-django Features Add and delete blog post View someone else blog Can add comment to that blog And o

Manish Jalui 1 Sep 12, 2022
Exploit Discord's cache system to remote upload payloads on Discord users machines

Exploit Discord's cache system to hide payloads PoC Remote upload embedded payload from image using EOF to Discord users machines through cache. Depen

cs 169 Dec 20, 2022
WeatherApp - Simple Python Weather App

Weather App Please star this repo if you like ⭐ It's motivates me a lot! Stack A

Ruslan Shvetsov 3 Apr 18, 2022
Актуальный сборник шаблонов для создания проектов и приложений на Django

О чем этот проект Этот репозиторий с шаблонами для быстрого создания Django проекта. В шаблоне проекта настроены следующий технологий: Django gunicorn

Denis Kustov 16 Oct 20, 2022
Django Pickled Model

Django Pickled Model Django pickled model provides you a model with dynamic data types. a field can store any value in any type. You can store Integer

Amir 3 Sep 14, 2022
TinyMCE integration for Django

django-tinymce django-tinymce is a Django application that contains a widget to render a form field as a TinyMCE editor. Quickstart Install django-tin

Jazzband 1.1k Dec 26, 2022
Djangoblog - A blogging platform built on Django and Python.

djangoblog 👨‍💻 A blogging platform built on Django and Python

Lewis Gentle 1 Jan 10, 2022
A reusable Django app that configures your project for deployment

django-simple-deploy This app gives you a management command that configures your project for an initial deployment. It targets Heroku at the moment,

Eric Matthes 205 Dec 26, 2022
Django REST Client API

Django REST Client API Client data provider API.

Ulysses Monteiro 1 Nov 08, 2021