Cross Site Request Forgery Production

I received a 403 Forbidden Error.

It reads:
" In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django’s CSRF mechanism has not been used correctly. For POST forms, you need to ensure:

  • Your browser is accepting cookies.

  • The view function passes a request to the template’s render method. → I am trying to access the /admin page.

  • In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.

  • If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data. → I am ussing CSRF View Middlwhere so we are good there.

  • The form has a valid CSRF token. After logging in in another browser tab or hitting the back button after a login, you may need to reload the page with the form, because the token is rotated after a login."

What have I tried and what am I expecting?

I retraced my steps in Django for Beginners book to see if I mistyped something. According to the instructions "


Our message board app requires that we log into the admin on the production website to create, read, update, or delete posts. We must make sure that CSRF_TRUSTED_ORIGINS101 is correctly configured since it is a list of trusted origins for unsafe HTTP requests like POST. For now, we can set it to https://* since that will match our eventual production URL. This approach is also slightly insecure–it would be better to enter the exact production URL address–but it is fine for now. Later on, in the book, we will lock done CSRF_TRUSTED_ORIGINS fully. At the bottom of the django_project/ file add a new line for CSRF_TRUSTED_ORIGINS"

# django_project/
CSRF_TRUSTED_ORIGINS = ["https://*"] # new

Here is my

# Quick-start development settings - unsuitable for production
# See

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-!qh!i)qrch6^r34#&qtf@-29ff+vzh7gd76d26eiifm$d1@bzc"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True


# Application definition

    "whitenoise.runserver_nostatic", # added whitenoise
    "posts", # new 

] # during the HTTP Response phase middleware are called from the bottom up.

ROOT_URLCONF = "django_project.urls"

        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [BASE_DIR / "templates"], # new
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [

WSGI_APPLICATION = "django_project.wsgi.application"

# Database

    "default": {
        "default": env.dj_db_url("DATABASE_URL", default="sqlite:///db.sqlite3"),

# Password validation

        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",

# Internationalization



USE_I18N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)

STATIC_URL = "static/" # this refers to the URL location of all static files in production.
STATIC_ROOT = BASE_DIR / "staticfiles" # new 

# Default primary key field type

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

CSRF_TRUSTED_ORIGINS = ["https://*"] # new

After doing that I checked Django Forums for what problems other people had. One user posted this link to the documentation.

I am not certain what to do here. Can someone give me advice?

Is that the actual url you are using to access your site? If not, on what url does your site reside?

i opened my website with: