Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
nginx deployment issues on aws alb host not found
error am getting in my web server container 2022-02-26 23:02:312022/02/26 22:02:31 [notice] 22#22: exiting 2022-02-26 23:00:432022/02/26 22:00:43 [error] 23#23: *13 django_web could not be resolved (3: Host not found), client: 10.0.1.89, server: enum-ops-staging.enum.africa, request: "GET / HTTP/1.1", host: "10.0.1.68" 2022-02-26 23:00:4310.0.1.89 - - [26/Feb/2022:22:00:43 +0000] "GET / HTTP/1.1" 502 157 "-" "ELB-HealthChecker/2.0" "-" 2022-02-26 23:00:432022/02/26 22:00:43 [error] 23#23: *12 django_web could not be resolved (3: Host not found), client: 10.0.0.59, server: enum-ops-staging.enum.africa, request: "GET / HTTP/1.1", host: "10.0.1.68" 2022-02-26 23:00:4310.0.0.59 - - [26/Feb/2022:22:00:43 +0000] "GET / HTTP/1.1" 502 157 "-" "ELB-HealthChecker/2.0" "-" my nginx.conf file server { listen 80; server_name enum-ops-staging.enum.africa; location / { resolver 10.0.0.2 valid=300s; set $backend http://django_web:8000; proxy_pass $backend; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_redirect off; } location /static { alias /usr/src/app/enumops/static; } location /media { alias /usr/src/app/enumops/media; } } tried a lot of suggestions but none seems to be working. Please any suggestions or help, thanks in advance?? -
How to access an object's fields and manipulate them when using pre_delete?
I have a foreign key in the model and I want to change a field's value in that object when pre_delete is called. I'm new to this concept and just found out that you use a pre delete signal like this: @receiver(pre_delete, sender=MyModel) def bid_deletion(sender, instance, using, **kwargs): pass What should I write to use the foreign key object's field? -
Django annotate() is not adding up the number of entries but is instead repeating them
Background: The Amazon Kindle PaperWhite stores the words we lookup while reading into a sqlite3 database called vocab.db. I am working on a small kindle companion app that takes this db file and imports it into a django table for various processing. I have done this step already. What I would like to do: I would like to query my table KindleLookups for my most difficult words (ex: how many times have I looked up a specific word). I would ultimately like to present this data in a table ordered by highest count. Desired Result: Word Lookup Count Reverberated 3 Troubadour 1 Corrugated 1 My result (undesired): Here Reverberated is being repeated three times each with a lookup count of one, instead of one time with three lookup count. Word Lookup Count Reverberated 1 Reverberated 1 Reverberated 1 Troubadour 1 Corrugated 1 Model: class KindleLookups(TimeStampedModel): book = models.ForeignKey(KindleBookInfo, on_delete=models.CASCADE) word = models.ForeignKey(KindleWords, on_delete=models.CASCADE) ... class KindleWords(TimeStampedModel): word_key = models.CharField(max_length=255, unique=True) word = models.CharField(max_length=255) ... I am trying to accomplish this using annotate(), but this is repeating the rows instead of adding them up for some reason. context['lookup_counts'] = KindleLookups.objects.annotate(word_count=Count("word")) I then thought that I needed to annotate on the actual … -
creating models using foreign key relationships
I have a user model that looks like this class User(AbstractUser): email = models.EmailField(verbose_name='E-mail', max_length=255, unique=True) first_name = models.CharField(verbose_name='First Name', max_length=255) last_name = models.CharField(verbose_name='Last Name', max_length=255) is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=False) is_superuser = models.BooleanField(default=False) is_teacher = models.BooleanField(default=False) is_student = models.BooleanField(default=False) username = None teacher = models.OneToOneField(Teacher, on_delete=models.CASCADE, related_name='teacher') student = models.OneToOneField(Student, on_delete=models.CASCADE, related_name='student') objects = UserManager() USERNAME_FIELD = 'email' REQUIRED_FIELDS = ['first_name', 'last_name'] def get_full_name(self): return self.first_name + " " + self.last_name def get_short_name(self): return self.first_name def __str__(self): return self.email My User Manager class UserManager(BaseUserManager): def create_user(self, email, first_name, last_name, password=None, **extra_fields): if not email: raise ValueError("Users must have an email address") if not first_name: raise ValueError("Users must have a first name") if not last_name: raise ValueError("Users must have a last name") if not password: raise ValueError("Users must have a password") user = self.model( email=self.normalize_email(email), ) user.first_name = first_name user.last_name = last_name user.set_password(password) user.is_staff = False user.is_superuser = False user.is_active = True user.teacher = Teacher.objects.create() user.student = Student.objects.create() user.save(using=self._db) return user def create_superuser(self, email, first_name, last_name, password=None, **extra_fields): if not email: raise ValueError("User must have an email") if not password: raise ValueError("User must have a password") if not first_name: raise ValueError("User must have a first name") if not last_name: … -
Django - User info not going to the database (e-commerce website)
I am trying to make an e-commerce website using Django where "AnonymousUser" or Guest user can also order and check out products without the need to login. The Guest user just need to provide their name, email, and address. But I want to get the name and email that was entered in the checkout form to the database: Customer table. I tried to use this as an alternative because when I check the info in the daatabase there's an error that says "__str__ returned non-string (type NoneType)": class Customer(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, null=True, blank=True) name = models.CharField(max_length=200, null=True) email = models.CharField(max_length=200) def __str__(self): return self.name or 'AnonymousUser' When I remove the or 'AnonymousUser' the error keeps on showing. Here's my checkout.html file: {% extends 'store/main.html' %} {% load static %} {% block content %} <div class="row"> <div class="col-lg-6"> <div class="box-element" id="form-wrapper"> <form id="form"> <div id="user-info"> <div class="form-field"> <input required class="form-control" type="text" name="name" placeholder="Name.."> </div> <div class="form-field"> <input required class="form-control" type="email" name="email" placeholder="Email.."> </div> </div> <div id="shipping-info"> <hr> <p>Shipping Information:</p> <hr> <div class="form-field"> <input class="form-control" type="text" name="address" placeholder="Address.."> </div> <div class="form-field"> <input class="form-control" type="text" name="city" placeholder="City.."> </div> <div class="form-field"> <input class="form-control" type="text" name="state" placeholder="State.."> </div> <div class="form-field"> <input class="form-control" type="text" … -
when sent via email the <a> tab is unclickable
<tr style="border: 0 none; border-collapse: separate;"> <td class="c-rdekwa" style="border: 0 none; border-collapse: separate; vertical-align: middle; padding-top: 38px;" valign="middle"><a href="reset-password.html" target="_blank" style="color: #000000; -webkit-border-radius: 4px; font-family: &quot; HelveticaNeueMedium&quot;,&quot;HelveticaNeue-Medium&quot;,&quot;HelveticaNeueMedium&quot;,&quot;HelveticaNeue&quot;,&quot;HelveticaNeue&quot;,sans-serif;font-weight: 500; font-size: 13.63636px; line-height: 15px; display: inline-block; letter-spacing: .7px; text-decoration: none; -moz-border-radius: 4px; -ms-border-radius: 4px; -o-border-radius: 4px; border-radius: 4px; background-color: green; color: #ffffff; padding: 12px 24px;">Recover my password</a> </td> </tr> the above code is the area that is of concern. the recover email link is working locally but once it is sent via email it doesn't work in the sense that it doest redirect nor take you anywhere its if its unclickanle <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office"> this code is what I have at the top I removed it and used only <head> still didn't work please I need help -
Django Importing Random Libraries?
Sometimes when I recompile or rerun my Django application, Django will import libraries at random that it then can't find. ie from cgi import test from distutils.command.clean import clean from winreg import SetValue return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 848, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/home/pweyand/NEST/lightchan/lightchan/backend/lightchan/lightone/urls.py", line 3, in <module> from . import views File "/home/pweyand/NEST/lightchan/lightchan/backend/lightchan/lightone/views.py", line 3, in <module> from winreg import SetValue ModuleNotFoundError: No module named 'winreg' What gives? Is there any way to turn this off? -
localhost: A server error occurred. Please contact the administrator
I am learning to run local hosts using Django with the help of https://www.dj4e.com/. I am currently trying to run the local server using the following: python manage.py runserver When I run this, the output given in terminal is the following: Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). February 26, 2022 - 15:21:09 Django version 3.2.5, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. I clicked into 127.0.0.1:8000, but the server outputs the error in the title, A server error occurred. Please contact the administrator. My terminal also outputs the following error: Traceback (most recent call last): File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run self.result = application(self.environ, self.start_response) File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__ return self.application(environ, start_response) File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__ return self.application(environ, start_response) TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given [26/Feb/2022 15:13:30] "GET / HTTP/1.1" 500 59 Traceback (most recent call last): File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run self.result = application(self.environ, self.start_response) File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__ return self.application(environ, start_response) File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__ return self.application(environ, start_response) TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given [26/Feb/2022 … -
Ubuntu: Trying startserver in Django and i get core exception update sqlite3. How can i update it. I am not strong in terminal commands
File "/usr/lib64/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 63, in check_sqlite_version raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version) django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17) -
Cannot assign "<User: Euler>": "Article.authorr" must be a "User" instance
what is problem? def change_names_of_field(apps, schema_editor): Article = apps.get_model('blog', 'Article') article = Article.objects.all() for s in article: s.authorr = User.objects.get(username=s.author) if Category.objects.filter(title=s.category).values_list("title", flat=True) == []: Category.objects.create(title=s.category) s.categoryy = Category.objects.filter(title=s.category) s.update = s.created s.published = s.created s.status = "p" s.save() -
how to store number of occurance of tags in post in django by creating custome table?
i am using spacy to generate tags for my posts by getting the words with maximum occurrence . and i have tag model and post model and i want to generate count model for storing tag with post with occurrence of tag in that post. class Occurrence(models.Model): number = models.IntegerField(unique=True) def __str__(self): return str(self.number) class TagPostOccurrenceLength(models.Model): number = models.ForeignKey( Occurrence, on_delete=models.CASCADE, related_name='numbers' ) tag = models.ForeignKey( MyCustomTag, on_delete=models.CASCADE, related_name='post_occurrence' ) post = models.ForeignKey( Post, on_delete=models.CASCADE, related_name='posts_occuraces' ) def __str__(self): return f'[{self.number} X {self.tag}] in: {self.post}' -
Django - store.models.Customer.MultipleObjectsReturned: get() returned more than one Customer -- it returned 2"
I am trying to make an e-commerce website where "AnonymousUser" or Guest user can order and check out products by providing their name, email, and address. But after clicking the "Make Payment" button, my terminal was having an error that says "store.models.Customer.MultipleObjectsReturned: get() returned more than one Customer -- it returned 2!" When I try to login and do the process for an authenticated user, it doesn't have an error. It just happen to AnonymousUsers. Here's my checkout.html: {% extends 'store/main.html' %} {% load static %} {% block content %} <div class="row"> <div class="col-lg-6"> <div class="box-element" id="form-wrapper"> <form id="form"> <div id="user-info"> <div class="form-field"> <input required class="form-control" type="text" name="name" placeholder="Name.."> </div> <div class="form-field"> <input required class="form-control" type="email" name="email" placeholder="Email.."> </div> </div> <div id="shipping-info"> <hr> <p>Shipping Information:</p> <hr> <div class="form-field"> <input class="form-control" type="text" name="address" placeholder="Address.."> </div> <div class="form-field"> <input class="form-control" type="text" name="city" placeholder="City.."> </div> <div class="form-field"> <input class="form-control" type="text" name="state" placeholder="State.."> </div> <div class="form-field"> <input class="form-control" type="text" name="zip" placeholder="zip code.."> </div> </div> <hr> <input id="form-button" class="btn btn-success btn-block" type="submit" value="Continue"> </form> </div> <br> <div class="box-element hidden" id="payment-info"> <small>Paypal Options</small> <button id="make-payment">Make Payment</button> </div> </div> <div class="col-lg-6"> <div class="box-element"> <a class="btn btn-outline-dark" href="{% url 'cart' %}">&#x2190; Back to Cart</a> <hr> <h3>Order Summary</h3> <hr> … -
django mock sms send
I have a method that sends sms to your phone, how can I mock it? services.py def send_msg(phone_number): url = settings.SMS_API_URL params = { ... } resp = requests.get(url, params) status_code = resp.json().get('status_code') return status_code tests.py @pytest.mark.django_db // mock it def test_sms_send(api_client): data = { 'phone_number': 'some_valid_phone_number' } response = api_client.post(reverse('phone_verify'), data=data) assert response.status_code == status.HTTP_200_OK -
how to calculate elo efficiently in django?
I'm managing ORM to update ELO rating, but this is hard for me. This is ELO model table. If I insert data between those instances, what will happen? id| league | match_date | player | rating --+--------+------------+---------+-------- 1| 1| 2022-01-01| AAA| 1015.0 (winner) 2| 1| 2022-01-01| BBB| 985.0 (loser) 3| 1| 2022-01-03| CCC| 1016.4 ... 4| 1| 2022-01-03| AAA| 999.4 ... 5| 2| 2022-01-05| AAA| 1015.0 6| 2| 2022-01-05| BBB| 985.0 7| 2| 2022-01-07| CCC| 1015.0 8| 2| 2022-01-07| BBB| 985.0 ... ... data to be inserted => ( league = 1, match_date = 2022-01-02, player = [AAA, CCC] (first is winner) ) Ordering of table is league ASC, match_date ASC. So data will be inserted to between second row and third row. However, rating values what after inserted data isn't currect. What I searching is how to update rating efficiently? Do I run for loop for update all ratings? In my opinion this will be create lots of Hits to DB. I've already created ORM using Subquery, but Subquery doesn't calculate based on calculated data, instead of data from table. It is deprecated because I inserted data. Is there any method using ORM to solve this problem, reply to … -
How to make login in django through a different table than auth_users?
Not sure what I am doing wrong I will leave below my files. The register method works perfectly but when I am doing the login, everytime the output is user is none. Does anyone know what I did wrong? I read the documentation of authentication with django but I cannot spot the problem. I saw that there were some questions about this problem, but I couldn't solve mine. settings.py AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',) urls.py urlpatterns = [ path('admin/', admin.site.urls), path('register/', views.registerMethod, name="register"), path('login/', views.loginMethod, name="login"), path('', include("main.urls")), path('', include("django.contrib.auth.urls")), ] views.py def registerMethod(request): if request.method=='POST': if request.POST.get('email') and request.POST.get('firstname') and request.POST.get('lastname') and request.POST.get('password'): user = NewUser() user.first_name = request.POST.get('firstname') user.last_name = request.POST.get('lastname') user.password = request.POST.get('password') user.email = request.POST.get('email') password = user.password.encode('utf-8') # Hash the ecoded password and generate a salt: hashedPassword = bcrypt.hashpw(password, bcrypt.gensalt(10)) user.password = str(hashedPassword) user.first_name = CleanString(user.first_name) user.last_name = CleanString(user.last_name) user.email = CleanString(user.email) message = None if UserExistsByEmail(user.email): message = 'You are already registered!' return render(request, 'register/register.html', {"message":message}) else: user.save() message = 'You have succesfully created an account!' return render(request, 'registration/login.html', {"message":message}) else: return render(request, 'register/register.html') else: return render(request, 'register/register.html') def loginMethod(request): if request.method == "POST": email = request.POST.get('email') password = request.POST.get('password') user = authenticate( email=email, password=password) if … -
How to solve coursera assigiment?
For this assignment work through Part 2 of the Django tutorial a [For this assignment work through Part 2 of the Django tutorial ] -
"from storages.backends.s3boto3 import S3Boto3Storage" not working
I imported django-storages and boto3 to my virtual enviroment and i am running the program within it but "storages.backends.s3boto3 import S3Boto3Storage" is not being recognized as a library and I am stumped. -
How to call a function when you delete a model object in django admin page? (or override delete action?)
I need to call a function whenever I have an object of a model deleted via admin page. How can I do such thing? -
Django error : exceptions caused by format_suffix_patterns are.error: redefinition of group name 'id' as group 2; was group 1 at position 56
my code works fine in my old computer, but I changed my computer suddenly I get this error, I couldn't fix it error: Traceback (most recent call last): File "/manage.py", line 22, in <module> main() File "/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/my_env/lib/python3.8/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line utility.execute() File "/my_env/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/my_env/lib/python3.8/site-packages/django/core/management/base.py", line 373, in run_from_argv self.execute(*args, **cmd_options) File "/my_env/lib/python3.8/site-packages/django/core/management/base.py", line 412, in execute self.check() File "/my_env/lib/python3.8/site-packages/django/core/management/base.py", line 438, in check all_issues = checks.run_checks( File "/my_env/lib/python3.8/site-packages/django/core/checks/registry.py", line 77, in run_checks new_errors = check(app_configs=app_configs, databases=databases) File "/my_env/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config return check_resolver(resolver) File "/my_env/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver return check_method() File "/my_env/lib/python3.8/site-packages/django/urls/resolvers.py", line 449, in check messages.extend(check_resolver(pattern)) File "/my_env/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver return check_method() File "/my_env/lib/python3.8/site-packages/django/urls/resolvers.py", line 449, in check messages.extend(check_resolver(pattern)) File "/usr/lib/python3.8/sre_parse.py", line 443, in _parse_sub itemsappend(_parse(source, state, verbose, nested + 1, File "/usr/lib/python3.8/sre_parse.py", line 831, in _parse raise source.error(err.msg, len(name) + 1) from None re.error: redefinition of group name 'id' as group 2; was group 1 at position 56 anyone knows how can i fix it? -
How can I show randomly different data for each user in Django?
I have a tag system in Django with the following model; class Data(models.Model): new = models.ChardField() is_tagged = models.BooleanField(default=False) class Tag(models.Model): data = models.ForeignKey(Data,on_delete=models.CASCADE,related_name="data") status = models.CharField(verbose_name="New Status",max_length=10,null=True) This model holds "positive", "negative", and "pass". There is a page called "new tags" and around 100 users will enter the page at the same time. There are 10000 data and users will enter the page and just click "positive", "negative", and "pass". I want to show different data for each user. It will prevent the users not seeing the same data and tagging the data 2 times. Let's say a user tagged the new as "positive". If I will send the new with random() it can be the same at another user unluckily. And the user can tag as "pass". This status will make "Data" "is_tagged" False. But other users tagged "positive" before. How can I prevent users see the same data at the same time? -
how can I send a message from a view to another view when use reverse in Django
I have 2 views for inserting phone number and another view is used to verify OTP code, now I want to send a message from verify view to the previous view that shows verify code is not valid or the time has expired. this view just check phone number that registar or not def manage_account(request,): form = RegisterForm(request.POST) if request.method == 'POST': # if user is exist just login else make user try: if 'phone_number' in request.POST: phone_number = request.POST.get('phone_number') user = UserPhone.objects.get(phone_number=phone_number) # send OTP otp = helper.get_random_otp() # helper.send_otp(phone_number, otp) # save otp user.otp = otp print('OTP:', otp) user.save() request.session['user_phone'] = user.phone_number # redirect to verify page return HttpResponseRedirect(reverse('verify')) except UserPhone.DoesNotExist: form = RegisterForm(request.POST) if form.is_valid(): user = form.save(commit=False) # send otp otp = helper.get_random_otp() # helper.send_otp(phone_number, otp) # save otp user.is_active = False user.otp = otp print('OTP:', otp) user.save() # for send a value to other pages request.session['user_phone'] = user.phone_number # redirect to verify page return HttpResponseRedirect(reverse('verify')) return render(request, 'registration/login.html', {'form': form, }) this view for verify OTP Code if is not valid or time has expired it reverse to manage_accout view that I want to send a message too. def verify(request): # for get value from … -
Move data from MySQL to PostgreSQL in Django application
I would like to move entire database in my Django app from MySQL to PostgreSQL. I now how to create such database, how to migrate tables but I am worried about user accounts and data that is on other tables. There is a lot of data there so I would like to know how in smart and efficient way move all data to PostgreSQL. Both databases are hosted on Azure. -
Django and React - npm run watch/build very slow
I'm trying to make a django/drf and react project but it takes 15+ seconds for npm run build to finish. What are my options here? It's not feasible to wait that long after every change I make to the front end. Should I keep the react and django parts separate till the end? I followed these instructions since I'm new to npm: https://medium.com/how-to-react/use-npm-watch-to-auto-build-your-reactjs-app-6ed0e5d6cb00 -
Using reportlab to create watermark on a pdf, how do I place the text on the top left hand corner
I have this code, what it does is it converts images to pdf and add a generated name to to the top left corner of the pdf. problem is the last part, the text placement is not where I want it to be,the top left corner. I am using reportlab and PIL import sys from PIL import Image from io import BytesIO from django.core.files.uploadedfile import InMemoryUploadedFile from PyPDF2 import PdfFileWriter, PdfFileReader from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter can = canvas.Canvas(packet, pagesize=letter) can.drawString(10, 100, name) can.save() packet.seek(0) new_pdf = PdfFileReader(packet) existing_pdf = PdfFileReader(document, "rb") output = PdfFileWriter() # add the "watermark" (which is the new pdf) on the existing page page = existing_pdf.getPage(0) page2 = new_pdf.getPage(0) page.mergePage(page2) output.addPage(page) # finally, write "output" to a real file buf = BytesIO() # outputStream = open(f"{name}.pdf", "wb") output.write(buf) buf.seek(0) What's the solution to this? any resources maybe in the documentation will be helpful. -
Issue with s3 bucket for STATIC FILES and Django
Something weird is happening and it might be an easy fix, but for the life of me I cant figure it out. When I use AWS_S3_CUSTOM_DOMAIN my website wont launch the static files but if i ignore the custom domain it works. if i use this it works fine # AWS SETTINGS AND ENVIROMENTVARIABLES 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_CUSTOM_DOMAIN = "%s.s3.amazonaws.com" % AWS_STORAGE_BUCKET_NAME AWS_S3_OBJECT_PARAMETERS = {"CacheControl": "max-age=86400"} # AWS_DEFAULT_ACL = None AWS_LOCATION = "static" STATICFILES_DIRS = [ os.path.join(BASE_DIR, "spotify/static"), ] STATIC_URL = "https://%s/%s/" % (AWS_STORAGE_BUCKET_NAME, AWS_LOCATION) STATICFILES_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" # AWS_S3_FILE_OVERWRITE = False # AWS_DEFAULT_ACL = None DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" AWS_S3_REGION_NAME = "us-east-2" AWS_S3_SIGNATURE_VERSION = "s3v4" but if i use this way, which is how everyone usually does it, it wont find the correct files # AWS SETTINGS AND ENVIROMENTVARIABLES 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_CUSTOM_DOMAIN = "%s.s3.amazonaws.com" % AWS_STORAGE_BUCKET_NAME AWS_S3_OBJECT_PARAMETERS = {"CacheControl": "max-age=86400"} # AWS_DEFAULT_ACL = None AWS_LOCATION = "static" STATICFILES_DIRS = [ os.path.join(BASE_DIR, "spotify/static"), ] STATIC_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION) STATICFILES_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" # AWS_S3_FILE_OVERWRITE = False # AWS_DEFAULT_ACL = None DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" AWS_S3_REGION_NAME = "us-east-2" AWS_S3_SIGNATURE_VERSION = "s3v4"