I am getting error page after admin panel post: 403 not found

Hello, my project, which works fine on localhost, started giving 403 errors after post operations when I uploaded it to the host.

I can log in in the admin panel, when I add a new user, it does the process successfully, but I get a 403 error on the return page.

I do not get an error when I act on the view side of the site, but I get this error when I post from the admin.

error page:

urls.py

from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
from django.contrib.sitemaps.views import sitemap
from home.sitemap import StaticViewSitemap

sitemaps = {
  'static':StaticViewSitemap
}

urlpatterns = [
  path('admin/', admin.site.urls),
  path('', include("home.urls"), name="anasayfa"),    
  path('sitemap.xml', sitemap, {"sitemaps":sitemaps}, name="sitemaps")
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

if settings.DEBUG:
  urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

home urls.py

from django.contrib import admin
from django.urls import path
from django.views.generic import TemplateView
from . import views

app_name = "home"

urlpatterns = [
  path(r'', views.index, name="anasayfa")
  path(r'galeri', views.galeri, name="galeri"),
]

models.py

from django.db import models
class Galeri(models.Model):
  baslik = models.CharField(max_length=255,null=True,blank=True, verbose_name="Başlık")
  resim = models.ImageField(blank=True, null=True, verbose_name="Fotoğraf Ekle")

class Video(models.Model):
 baslik = models.CharField(max_length=255, null=True, blank=True, verbose_name="Başlık")
 video = models.FileField(upload_to="video", blank=True, null=True)

settings.py


from pathlib import Path
import os

BASE_DIR = Path(__file__).resolve().parent.parent


SECRET_KEY = '8sp0csz+wrtku=7$$z=z786#(l+bn0rujh2ol-3#-h5bpn-l&d6*ngp9xg'


DEBUG = True
#DEBUG_PROPAGATE_EXCEPTIONS = True

ALLOWED_HOSTS = ['56.225.209.124','domain.com']
CSRF_TRUSTED_ORIGINS = ['https://domain.com']
CSRF_COOKIE_SECURE = False
SESSION_COOKIE_SECURE = False

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    "home",
    "upadmin",
    'django.contrib.sites',
    'django.contrib.sitemaps',
    
]

SITE_ID = 1

MIDDLEWARE = [
    
    'htmlmin.middleware.HtmlMinifyMiddleware',
    'htmlmin.middleware.MarkRequestMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'umy.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "templates")],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'umy.wsgi.application'



DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


AUTH_PASSWORD_VALIDATORS = [
    {
        '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',
    },
]


LANGUAGE_CODE = 'tr'

TIME_ZONE = 'Europe/Istanbul'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_ROOT = "C:/inetpub/vhosts/domain.com/httpdocs/static/"
#STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

#STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

NOT: I am using windows server.

How are you running this on the server?

Wfastcgi I used

The video I took into account when posting

Unfortunately, I don’t think I can help you here. I’ve never deployed Django under IIS.

If you have WSGI_LOG set in your IIS settings, what error message(s) are being logged there? Hopefully there might be some information in that file that would help.

Also, seeing your IIS configuration for this may be helpful.

Hello, when I show the error codes, the error I get is as follows.

web.config folder:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="c:\python39\python.exe|c:\python39\lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
    <httpErrors errorMode="Detailed">
      <remove statusCode="400" />
      <error statusCode="400" path="C:\Inetpub\vhosts\domain.com\error_docs\bad_request.html" />
      <remove statusCode="401" />
      <error statusCode="401" path="C:\Inetpub\vhosts\domain.com\error_docs\unauthorized.html" />
      <remove statusCode="403" />
      <error statusCode="403" path="C:\Inetpub\vhosts\domain.com\error_docs\forbidden.html" />
      <remove statusCode="404" />
      <error statusCode="404" path="C:\Inetpub\vhosts\domain.com\error_docs\not_found.html" />
      <remove statusCode="405" />
      <error statusCode="405" path="C:\Inetpub\vhosts\domain.com\error_docs\method_not_allowed.html" />
      <remove statusCode="406" />
      <error statusCode="406" path="C:\Inetpub\vhosts\domain.com\error_docs\not_acceptable.html" />
      <remove statusCode="407" />
      <error statusCode="407" path="C:\Inetpub\vhosts\domain.com\error_docs\proxy_authentication_required.html" />
      <remove statusCode="412" />
      <error statusCode="412" path="C:\Inetpub\vhosts\domain.com\error_docs\precondition_failed.html" />
      <remove statusCode="414" />
      <error statusCode="414" path="C:\Inetpub\vhosts\domain.com\error_docs\request-uri_too_long.html" />
      <remove statusCode="415" />
      <error statusCode="415" path="C:\Inetpub\vhosts\domain.com\error_docs\unsupported_media_type.html" />
      <remove statusCode="500" />
      <error statusCode="500" path="C:\Inetpub\vhosts\domain.com\error_docs\internal_server_error.html" />
      <remove statusCode="501" />
      <error statusCode="501" path="C:\Inetpub\vhosts\domain.com\error_docs\not_implemented.html" />
      <remove statusCode="502" />
      <error statusCode="502" path="C:\Inetpub\vhosts\domain.com\error_docs\bad_gateway.html" />
      <remove statusCode="503" />
      <error statusCode="503" path="C:\Inetpub\vhosts\domain.com\error_docs\maintenance.html" />
    </httpErrors>
    <tracing>
      <traceFailedRequests>
        <clear />
      </traceFailedRequests>
    </tracing>
        <defaultDocument>
            <files>
                <add value="Index.py" />
            </files>
        </defaultDocument>
  </system.webServer>
  <appSettings>
    <add key="WSGI_HANDLER" value="umy.wsgi.application" />
    <add key="DJANGO_SETTINGS_MODULE" value="umy.settings" />
    <add key="PYTHONPATH" value="C:\Inetpub\vhosts\domain.com\httpdocs" />
  </appSettings>
  <system.web>
    <compilation tempDirectory="C:\Inetpub\vhosts\domain.com\tmp" />
  </system.web>
</configuration>

Hopefully someone with knowledge of Django deployment under IIS will be able to assist you.

Which network are you using while publishing your web pages? Can you show me a source?

I’m not sure I understand what you’re asking for here.

I don’t deploy to Windows servers and I don’t use IIS. The vast majority of servers running the applications I write are Ubuntu systems running nginx / uwsgi. I’ve also got a couple running on Raspberry Pi. (I don’t think I have any more running on any RedHat-based instances such as CentOS or Fedora.)

1 Like

thanks for your help :pray:

hi its been a while. have you solved your problems while this time ? cause im facing the same.