Django.fun

Questions & Answers about Django, page 1775

Django, Apache2 and Mod_WSGI serves data slower than a fax miachine

I have a very basic Django instance set up on a RPi model 3. Important as this may indeed be the issue. I'm using Django 3.2, Python 3.7, Mod_WSGI, compiled from source against this version of python and Apache2, installed …

DJANGO ListView returns HTTPResponse, but I need a json

I am having a problem around the Class Based Views in Django. I need to create JSON responses, instead of rendering to a template. class AllItem(ListView): model = MyModel context_object_name = 'items' template_name = 'mymodel/index.html' I also have a …

Received(queue) or Executing multiple tasks at same time in celery

I added 10 tasks in celery process. It picks one by one (default celery process). After the completion of first task it picks the second task received and executed . Those tasks are not depending on each other. so I …

Django select multiple model instances of the same user

I have this: user = request.user notifications = Notification.objects.filter(user=user) budget = Budget.objects.filter(user=user) Is there a way to get this data into one query? I was looking into a Subquery or a join query, but I don't know if it …

How to make annotation for foreign key in Django?

I need to replace _points property by annotation so that I have the opportunity to sort entries in the Django admin panel by this value. My model: class CustomUser(models.Model): inviter = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True) @property def _points(self): res = …

How should I write a serializer where a foreign key cold be set by SlugRelatedField OR by the foreign key serializer?

I have a serializer as follow: class MySerializer(serializers.ModelSerializer): """ Serializer for mymodel """ version = VersionSerializer() device = DeviceSerializer() camera = CameraSerializer(many=True) My code needs to be able to create instance of mymodel knowing only one field on my …

I'd like to apply the code from the view to the template tag

I am a student who is learning Django. Code created in view to float an optionless product. I want to change this to a template tag and print out p-tags only for products without options, how can I change it? …

Debugger in Django not stopping at breakpoints after the initial setup

I'm having a problem with the debugger in Django (which I've run both by pressing the green arrow as well as F5). I've set a number of breakpoints on the URLs and the Views, and the debugger stops on the …

How to customize the admin dashboard for a specific model in Django when adding?

How customize the admin dashboard for a specific model in Django? I have some models. I want to add a JS or CSS file in the admin dashboard when I add an object?

You are trying to add a non-nullable field 'ArtsHumanities' to school without a default

I am currently working on a project in which we can make html table with the backend data(For more instance you can check the below given link ). I have made some try to make its model but unable to …

Templateview in django has gone error "Field 'id' expected a number but got 'form_file' "

This is my view.py file class UploadTemplateView(TemplateView): template_name = 'reports/from_file.html' This is my urls.py file urlpatterns = [ path('save/', create_report_view, name='create-report'), path('', ReportListView.as_view(), name='main'), path('from_file/', UploadTemplateView.as_view(), name='form-file'), path('<pk>/', ReportDetailView.as_view(), name='detail'), path('upload/', csv_upload_view, name='upload'), path('<pk>/pdf/', render_pdf_view, name='pdf'), ] When …

Serve React with docker and nginx, which is already serving django

I am creating a web-app using the django + react + nginx + docker tech-stack. I can successfully serve my django REST API, admin panel and its static files using nginx but cannot serve the react app after build. I …

Trying to fetch data from api by id search using flutter and the http.get is not parsing the data get from api

Future<List> fetchGraduates() async { var response = await http.get( Uri.parse('http://127.0.0.1:8000/graduates/image_api/A/ur4444/09')); var response2=await http.get( Uri.parse('http://127.0.0.1:8000/graduates/student_api/A/ur4444/09')); Map<String, dynamic> studentData = jsonDecode(response.body); Map<String, dynamic> imageData = jsonDecode(response2.body); Map<String, dynamic> data = { 'id': studentData['student'], 'first_name': studentData['first_name'], 'middle_name': studentData['middle_name'], 'last_name': studentData['last_name'], 'image': imageData['image'], 'institution': …

How to use serializer field and make response of the data from the choice field in django rest framework

How to use serializer field in DRF models.py class User(models.Model): id = models.AutoField(primary_key=True) first_name = models.CharField(max_length=255, null=True, unique=True) birthdate = models.DateField(null=True, blank=False) gender_choice = [ ('male','male'), ('female','female') ] gender = models.CharField(max_length=255, choices=gender_choice, default='male', null=True) the rest ans is in …

Django Rest Framweork - Why first pagination offset starts from 0 and how to change it to 1?

I am trying to create a custom Limit and Offset Paginator but first page starts from zero which I don't know why!. The offset limit is set to 1 but within url it starts from 0, what I want is …

Django App deployed on Heroku works despite wrong SECRET_KEY

In my Django project I have an .env file which holds my DJANGO_SECRET_KEY environment variable: export DJANGO_SECRET_KEY=dummysecretkey123 I added a reference to the .env file in my .gitignore file before I initialized the repo, so the SECRET_KEY should not …

Having trouble displaying entry posts and comments on front page

I have tried to solve this issue for at least 8 hours and I am probably missing something very simple. But since I am very new to programming I want to reach out for a little help. I am working …

Sending S/MIME Signed Mails with Django

Is there a way to use the wrappers provided by Django to send signed or even encrypted emails? We use S/MIME in our company and it's required that all mails are signed. I currently send emails via SendGrid: …

How do I store a cloned data into the database

I have the following page right now which is using django form with 3 different models and they are all linked upon saving. Image:Page shown upon adding new device But if i add another module and save. …

Can't pass String from react to django using axios

I'm trying to send a request from react to django that has the following body: { "category":"string" } I send the request from react like this: axiosInstance .get(`answers/`, { category:currentQuiz }).then((res) => { console.log(res.data) }) .catch((function (error) { console.log(error) …

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 →