Search code examples
pythondjangoamazon-web-servicesherokuboto3

ValueError at /profile/ Required parameter name not set Request Method: GET


After properly deploying my app using Heroku I get this error while accessing my profile.

ValueError at /profile/
Required parameter name not set
Request Method: GET
Request URL:    https://(domain).herokuapp.com/profile/
Django Version: 3.2.2
Exception Type: ValueError
Exception Value:    
Required parameter name not set
Exception Location: /app/.heroku/python/lib/python3.9/site-packages/boto3/resources/base.py, line 118, in __init__
Python Executable:  /app/.heroku/python/bin/python
Python Version: 3.9.5
Python Path:    
['/app/.heroku/python/bin',
 '/app',
 '/app/.heroku/python/lib/python39.zip',
 '/app/.heroku/python/lib/python3.9',
 '/app/.heroku/python/lib/python3.9/lib-dynload',
 '/app/.heroku/python/lib/python3.9/site-packages']
Server time:    Wed, 19 May 2021 18:40:44 +0000
Error during template rendering
In template /app/blog/templates/blog/base.html, error at line 10

Required parameter name not set
1   {% load static %}
2   <!DOCTYPE html>
3   <html>
4   
5   <head>
6       <link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}"/>
7   
8       <!-- Required meta tags -->
9       <meta charset="utf-8">
10      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
11  
12      <!-- Bootstrap CSS -->
13      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
14          integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
15  
16      <link rel="stylesheet" type="text/css" href=" {% static 'blog/main.css' %} ">
17  
18      {% if title %}
19      <title>mytitle -{{ title }} </title>
20      {% else %}

I don't understand why i keep getting this error. I have also set the environment variables correctly. This is my settings.py

import os
import django_heroku

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY= os.environ.get('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = (os.environ.get('DEBUG_VALUE') == 'True')

ALLOWED_HOSTS = ['yourlevelup.herokuapp.com']


# Application definition

INSTALLED_APPS = [
    'blog.apps.BlogConfig',
    'users.apps.UsersConfig',
    'crispy_forms',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'storages',
]

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 = 'django_project.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 = 'django_project.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

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',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

CRISPY_TEMPLATE_PACK = 'bootstrap4'

LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('USER_EMAIL')
EMAIL_HOST_PASSWORD = os.environ.get('USER_EMAIL_PASS')

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')

AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None

AWS_S3_REGION_NAME = 'ap-south-1'
AWS_S3_SIGNATURE_VERSION = 's3v4'
AWS_S3_ADDRESSING_STYLE = "virtual"


DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

django_heroku.settings(locals())

It says I have some error on my 10th line of base.html but it's the first time I get this error. Before the deployment, running locally, there was not any problem like this. Everything else runs smoothly. I have also restarted my console but still not working.


Solution

  • After I checked your site out and saw the full error message, it seemed that you did not set the os environment variable in your settings at AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME').

    If you read the error message on the site, you would’ve seen it say:

    /app/.heroku/python/lib/python3.9/site-packages/storages/backends/s3boto3.py, line 572, in url
            params['Bucket'] = self.bucket.name …
    name    'default.jpg'
    parameters  None
    

    Note the parameters None part, which means that the storage bucket name variable returns none which means you must have configured your environment settings incorrectly on heroku, and the os.environ.get('AWS_STORAGE_BUCKET_NAME') is returning Nothing. Check this out if you want to know how to set environment variables on heroku:https://devcenter.heroku.com/articles/config-vars

    fix: Just run this command using the heroku cli:

    heroku config:set AWS_STORAGE_BUCKET_NAME=your_name
    

    (Note you have to replace the your_name part with your Storage Bucket Name)