Не указано обязательное имя параметра - Django + Amazon S3 - PullRequest
0 голосов
/ 20 апреля 2020

Я пытаюсь настроить Amazon S3 для своего приложения Django, и мне постоянно говорят «Обязательное имя параметра не задано». Эта ошибка возникает, когда необходимо отобразить изображение. Например, он отлично работает на домашней странице, где нет изображений. На самом деле не знаю, где я ошибся. У меня есть следующие настройки в моем settings.py.

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

#S3 BUCKET CONFIG

AWS_ACCESS_KEY_ID = 'acccess key'
AWS_SECRET_ACCESS_KEY = 'secret access key'
AWS_BUCKET_NAME = 'bucket name'


AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

Полный возврат

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/projects/createListing

Django Version: 2.2
Python Version: 3.7.3
Installed Applications:
['projects',
 'users.apps.UsersConfig',
 'crispy_forms',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'storages']
Installed 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']


Template error:
In template C:\Users\Maksims\Desktop\CA4106-Cloud-Computing\test\src\personal_portfolio\templates\base.html, error at line 10
   Required parameter name not set
   1 : {% load static %}
   2 : <!doctype html>
   3 : <html lang="en">
   4 :   <head>
   5 :     <!-- Required meta tags -->
   6 :     <meta charset="utf-8">
   7 :     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
   8 : 
   9 :     <!-- Bootstrap CSS -->
   10 :     <link re l="stylesheet" href="https://stack path.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
   11 : 
   12 :     {% if title %}
   13 :       <title>Prestige Worldwide - {{ title }}</title>
   14 :     {% else %}
   15 :       <title>Prestige Worldwide - </title>
   16 :     {% endif %}
   17 :     
   18 :   </head>
   19 :   <body>
   20 :     <header class="site-header">


Traceback:

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in _resolve_lookup
  829.                     current = current[bit]

During handling of the above exception ('ImageFieldFile' object is not subscriptable), another exception occurred:

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\exception.py" in inner
  34.             response = get_response(request)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
  21.                 return view_func(request, *args, **kwargs)

File "C:\Users\Maksims\Desktop\CA4106-Cloud-Computing\test\src\projects\views.py" in createListing
  35.     return render(request, 'createListing.html', {'listing_form': link})

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\shortcuts.py" in render
  36.     content = loader.render_to_string(template_name, context, request, using=using)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\loader.py" in render_to_string
  62.     return template.render(context, request)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\backends\django.py" in render
  61.             return self.template.render(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render
  171.                     return self._render(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in _render
  163.         return self.nodelist.render(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render
  937.                 bit = node.render_annotated(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render_annotated
  904.             return self.render(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\loader_tags.py" in render
  150.             return compiled_parent._render(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in _render
  163.         return self.nodelist.render(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render
  937.                 bit = node.render_annotated(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render_annotated
  904.             return self.render(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\loader_tags.py" in render
  62.                 result = block.nodelist.render(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render
  937.                 bit = node.render_annotated(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render_annotated
  904.             return self.render(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render
  987.             output = self.filter_expression.resolve(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in resolve
  671.                 obj = self.var.resolve(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in resolve
  796.             value = self._resolve_lookup(context)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in _resolve_lookup
  837.                         current = getattr(current, bit)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\fields\files.py" in url
  62.         return self.storage.url(self.name)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\storages\backends\s3boto3.py" in url
  620.         params['Bucket'] = self.bucket.name

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\storages\backends\s3boto3.py" in bucket
  326.             self._bucket = self._get_or_create_bucket(self.bucket_name)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\storages\backends\s3boto3.py" in _get_or_create_bucket
  363.         bucket = self.connection.Bucket(name)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\boto3\resources\factory.py" in create_resource
  474.                            client=self.meta.client)(*args, **kwargs)

File "C:\Users\Maksims\AppData\Local\Programs\Python\Python37-32\lib\site-packages\boto3\resources\base.py" in __init__
  119.                     'Required parameter {0} not set'.format(identifier))

Exception Type: ValueError at /projects/createListing
Exception Value: Required parameter name not set

1 Ответ

0 голосов
/ 21 апреля 2020

как сказал @ jordanm2, у меня было AWS_BUCKET_NAME вместо AWS_STORAGE_BUCKET_NAME

...