djangoproject.com djangoproject.com

Refactoring Django model setup advice

As a learning exercise I am creating a way for generate Student Report Cards. I was able to create the desired outcome in the current version by hardcoding each Standard as its own field in the model but there was a lot of repetition and was hoping to improve it. Sample of current models.py with lots of repetition Sample of current forms.py with lots of repetition Current Front-End How can I re-create the formset above with less...

djangoproject.com djangoproject.com

Django doesn't submit my form if I using individual fields

I need to render my Django form fields individually because of design purposes. It looks good but if I hit submit It doesn't do anything just a short blink. If I render the whole {{ form }} it works well. I don't have any ideas about what am I doing wrong. Could you guys please help me? html <form method = "POST"> <div class="container w-75 bg-light rounded-3 pt-3"> <div...

djangoproject.com djangoproject.com

Why can't I upload a image by Django?

I'm going to make a book bulletin board using the django and put a picture of the book in it and post a post. But the text is going up, but the picture isn't going up. i add MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' in settings.py model.py class Book(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT) title = models.TextField() author =...

djangoproject.com djangoproject.com

Django security releases issued: 3.2.1, 3.1.9, and 2.2.21

In accordance with our security release policy, the Django team is issuing Django 3.2.1, Django 3.1.9, and Django 2.2.21. These release addresses the security issue detailed below. We encourage all users of Django to upgrade as soon as possible. CVE-2021-31542: Potential directory-traversal via uploaded files MultiPartParser, UploadedFile, and FieldFile allowed directory-traversal via uploaded files with suitably crafted file...

djangoproject.com djangoproject.com

Load data from models into HTML file by clicking button

I am trying to load data from my database into the same fields when a user clicks on load for a certain bla number. I am saving the data just fine and I can see it on the console but how do I get it to show up in the fields of the form? here is what I have: model: class Overview(models.Model): application_path = models.CharField(max_length=100) review_decision = models.CharField(max_length=100) bla_number =...

djangoproject.com djangoproject.com

Python Permission Denied with ffprobe on NamedTemporaryFile

I'm trying to validate certain parameters of a media file before the file gets saved in Django. So I validate the file using ffprobe (from the ffmpeg pip package). with NamedTemporaryFile(suffix=f'.{self.audio.name.split(".")[-1]}') as fp: fp.write(self.audio.read()) try: # Get duration with ffprobe info = probe(fp.name) self.duration = info['format']['duration'] fp.close() except...

djangoproject.com djangoproject.com

Django filter out on related field

I have three models, two of them linked to the third by a foreign key, as follows: class A(models.Model): sku = models.ForeignKey("SKU", on_delete=models.PROTECT) production_start = models.DateField(blank=True, null=True) production_end = models.DateField(blank=True, null=True) class B(models.Model): date = models.DateField() sku = models.ForeignKey("SKU", on_delete=models.PROTECT) quantity...

djangoproject.com djangoproject.com

Django internal server error - No module decouple

I am trying to deploy some basic django app on linode but I get error 500 whenever I try to access my website. Here are the files and logs tail -200 mysite-error.log [Mon May 03 17:00:53.788104 2021] [wsgi:error] [pid 10477:tid 139635748644416] [remote 85.68.32.122:57733] mod_wsgi (pid=10477): Failed to exec Python script file '/var/www/GreatKart/greatkart/wsgi.py'. [Mon May 03 17:00:53.788180 2021] [wsgi:error] [pid 10477:tid...

djangoproject.com djangoproject.com

django databaseerror on apache2 with uwsgi

It is a project that deloyed two years ago(no changes for about two years). But today it was reported crash. got the log as below(I replaced real project path with 'PATH/TO/PROJECT'). django.request - INFO - OK: / Traceback (most recent call last): File "/PATH/TO/PROJECT/venv/lib/python3.5/site-packages/django/contrib/sessions/backends/base.py", line 189, in _get_session return self._session_cache AttributeError:...

djangoproject.com djangoproject.com

Django/Python "django.core.exceptions.ImproperlyConfigured: Cannot import 'contact'. Check that '...apps.contact.apps.ContactConfig.name' is correct"

Hopefully you all can give me a hand with this... my work flow: |.vscode: |capstone_project_website: | -_pycache_: | -apps: | -_pycache_ | -accounts: | -contact: # app that is throwing errors | -_pycache_: | -migrations: | -_init_.py | -admin.py | -apps.py | -forms.py | -models.py | -test.py | -urls.py | -views.py | ...

djangoproject.com djangoproject.com

Why do I have a 'KeyError' error when using when using Django's coverage tool

Im developing a django API. Now im doing some tests on the endpoints and when i execute 'python manage.py test' everything goes well. But when i use the flag '--with-coverage' or 'coverage run --source='.' manage.py test app && coverage report' i get the error 'KeyError: 'BREAK_LOOP'. Someone can help me? Code from django.test import TestCase import requests class Teste(TestCase): url = "localhost://endpoint/" ...

djangoproject.com djangoproject.com

Nginx failing to serve django static or media files on digital ocean

I'm having issues serving static files and media files when I deploy my dockerised django app to digital ocean. I've read many similar questions on here, but none of the answers have worked for me so far. Roughly following this guide, https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/#nginx, I'm now in a state where I can spin up my docker container locally using the following commands and have nginx serve...