Django.fun

Questions & Answers about Django, page 1776

django template backend for Jinja2

is there difference between TEMPLATES = [ { 'BACKEND': 'django.template.backends.jinja2.Jinja2', ....... }, ] and (imported from django-jinja package) TEMPLATES = [ { "BACKEND": "django_jinja.backend.Jinja2", ....... }, ]

How to format django timezone.now()

The default format of django timezone.now() example Aug. 15, 2021, 1:00pm how to convert this into 2021-8-15 thanks in advance! Here is my models.py publish= models.DateTimeField(default=timezone.now()) i tried this: publish= models.DateTimeField(default=timezone.now().strftime('%Y-%m-%d')) but its not working , here is …

Django ModuleNotFoundError: No module named 'EmailIngestionDemo.EmailIngestionDemo'

Im trying to write a django web that will retrieve data from postgresql and display on it. But whenever I run my application it show me: from EmailIngestionDemo.EmailIngestionDemo.models import EmailData ModuleNotFoundError: No module named 'EmailIngestionDemo.EmailIngestionDemo' On my views.py …

My function call the return before the rest of the code

So I am trying to loop through the list of classes see if there is a match or not if there is a match return a Response and say there is a match otherwise register the student I am using …

Send data with POST-request wont work in Django with AJAX

First of all: I know, there are a few solutions for this online, but they wont work for me (because they use e.g. Jason or are just outdated) I work on a project in Django and want to use ajax …

DRF-How to save foreign keys data using APIView

everyone, I am absolutely a beginner in DjangoRestFramework. I have confusion to deal with relationships in DRF. How do I save foreign keys data using APIView? models class User(AbstractUser): email = models.EmailField(max_length=255, unique=True) is_client = models.BooleanField(default=False) is_professional = models.BooleanField(default=False) …

create multiple objects at the same time

I have this view that creates a form with groups and exercises. How can I do to be able to create more groups and exercises in the template? views.py @login_required def creaScheda(request): if request.method == "POST": form = CreaSchedaForm(request.POST) if …

How to create nested dictionary from two related models in Django?

I want to create dictionary format like ; { "2021": [ { "name": "John Doe", "date": "01.01.2021", "items": "item1" } ], "2020": [ { "name": "Jane Doe", "date": None, "items": "item2" }, { "name": "Jack Doe", "date": None, "items": …

Angular frontend not getting data from Django backend on Docker container

I have an app which uses Angular(with Nginx), Django and MySQL. Each of these are containerized separately on AWS Ubuntu instance. I have been able to connect from Django container to Mysql container and do migrations for Django. Neither the …

Django class base, forms.py, show diffrent forms dependent on if you are creating or updating

I have a forms.py that show a dropdown when creating. But I would like it to be a hidden field when updating. Is it possible to make forms.py show 2 diffrent views depending on you are creating or updating? asset …

change SQL query to Django

I have a web app, backend using Django. I want to change the following SQL query to Django ORM command: SELECT distinct t.id, t.title as Textbook, GROUP_CONCAT(concat(ci.discipline_code, ci.code, " (" , ci.type , ")") SEPARATOR ', ') as CourseCode …

How to update fields of related model in one query using Django ORM or SQL?

I want to update model fields and fields of related model in one query in Django: Link.objects.filter(alpha=True).update( alpha=False, target__backup_of_original_start=F('target__original_start'), target__backup_of_original_end=F('target__original_end'), target__original_start=F('target__start'), target__original_end=F('target__end'), ) In this question I see that it is impossible using update. Is it possible to …

Django Postgresql test database issue

I am pretty new to django and have an issue with the db. I tried to test a few things and got the following error: Creating test database for alias 'default'... .... RuntimeWarning: Normally Django will use a connection to …

Django _Categorize products

I want to show specific categories of items on a single page. Each category has a subheading and specific categories in the group. Whenever i run the enve, everything is good but each subcategories output all the products, even the …

why do I get error 500 when I fetch javascript? [closed]

I have a Django project and I want to update the model using the javascript fetch method put to update the value from true => false and vice versa. however, I get error 500 inbox.js:63 PUT http://127.0.0.1:8000/add-like/14 500 (Internal Server …

To output <p>tags using template tags

How can I use the template tag to create a &quot;p-tag only for products that do not have product_code in the option table&quot;? {% for option in option_object %} {{option.product_code}} {% if option.product_code == None %}} &lt;p&gt; hello &lt;/p&gt; {% …

Show fields passing through a ManyToMany field django admin

I'm working on a project developed in Python 2.7 and Django 1.11. I'm trying to show in admin page two fields passing through a ManyToMany field. Here the models: class ModelZero(Model): # some fields mtm_field = models.ManyToManyField(to=&quot;ModelOne&quot;, through=&quot;ModelTwo&quot;) class …

How to fetch the data for the current hour in Django

I am trying to fetch data from a django model while filtering its DateField() to the current date and current hour. models.py class Log(models.Model): DATE = models.DateTimeField() TYPE = models.CharField(max_length=32,primary_key=True) class Meta: db_table='LOG' indexes=[ models.Index(fields=['DATE','TYPE']) ] views.py obj=Log.objects.filter() …

Django adding new fields to external DB's model

I am trying to integrate some tables from an Oracle DB, which is not a part of my Django project. That DB has 2 tables of interest to me, with the first one having 90% of information, and the 2nd …

Python Speech to Text API (Postman)

I have written API for python speech to text and I want to test using postman so far I have tried this code but not be able to get the result. import speech_recognition as sr from flask import …

Tutorials

Современный Python: начинаем проект с pyenv и poetry

Настройка проекта Python — виртуальные среды и управление пакетами

Использование requests в Python — тайм-ауты, повторы, хуки

Понимание декораторов в Python

ProcessPoolExecutor в Python: полное руководство

map() против submit() с ProcessPoolExecutor в Python

Понимание атрибутов, словарей и слотов в Python

Полное руководство по slice в Python

Выпуск Django 4.0

Безопасное развертывание приложения Django с помощью Gunicorn, Nginx и HTTPS

Автоматический повтор невыполненных задач Celery

Django REST Framework и Elasticsearch

Докеризация Django с помощью Postgres, Gunicorn и Nginx

Асинхронные задачи с Django и Celery

Релизы безопасности Django: 3.2.4, 3.1.12 и 2.2.24

Выпуски исправлений ошибок Django: 3.2.3, 3.1.11 и 2.2.23

Эффективное использование сериализаторов Django REST Framework

Выпуски безопасности Django: 3.2.2, 3.1.10 и 2.2.22

Выпущенные релизы безопасности Django: 3.2.1, 3.1.9 и 2.2.21

Обработка периодических задач в Django с помощью Celery и Docker

View all tutorials →