C
C
Chikibombaster2022-03-31 16:14:11
Django
Chikibombaster, 2022-03-31 16:14:11

Django [Errno 13] Permission denied?

error when registering a user and redirecting him to the main page [Errno 13] Permission
denied
Every line return render(request, '') in views.py works, it throws an error
6245a9ee3b2a0048666132.png
settings.py

import os
from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

SECRET_KEY = ''

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

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    # 'sampleapp.apps.SuitConfig',
    'mathfilters',
    'main',
    'shop',
    'django.contrib.humanize',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

]

MIDDLEWARE = [
    '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 = 'clotheStore.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = '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 = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'

STATICFILES_DIRS = [
    BASE_DIR / "static",
]
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
LOGIN_REDIRECT_URL = '/'

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'


urls.py
from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='home'),
    path('create', views.create, name="create"),
    path('store', views.store, name="store"),
    path('call', views.call, name="call"),
]


views.py
from django.shortcuts import render, redirect
from .forms import callBackForm
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import authenticate, login
from . import urls



def index(request):
    type=''
    return render(request, 'shop/example.html', {'type': type})


def create(request):
    error = ''
    sec = ''
    if request.method == 'POST':
        form = UserCreationForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            password2 = form.cleaned_data.get('password2')
            # return render(request, '')
            if password == password2:

                form.save()
                user = authenticate(username=username, password=password)
                login(request, user)
                sec = f"{username}, {password}, {password2}, {user}"
                return render(request, '')
            else:
                error = "Passwords don't match"
        else:
            error = 'Form was incorrect'
            pass

    form = UserCreationForm()

    data = {
        'form': form,
        'error': error,
        'sec': sec
    }

    return render(request, 'registration/create.html', data)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2022-03-31
@bacon

Explain how such a call should work ? render(request, '')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question