"Вопросы и ответы" Django и Python

11.05.2024
DoesNotExist at /up_emp/31/

DoesNotExist at /up_emp/31/ Employee matching query does not exist. Request Method:POSTRequest URL:http://127.0.0.1:8000/up_emp/31/Django Version:5.0.6 Exception Type:DoesNotExistException Value:Employee matching query does not exist. While I was implementing CRUD operations in Django, I encountered some errors during the update process. Could you …

11.05.2024
How to use Discord Oauth2 with Allauth?

I've been working on a social media clone of mine for a few days and I now think that having discord as a method to signup and login would be really cool. How can I integrate it using only Allauth? …

11.05.2024
How to importing python class in django case

Why we import like this. from django.db.models import Model, Model class is inside base.py not models. expecting from django.db.models.base import Model, why base module ommitted. django/db/models/base.py is the structure

11.05.2024
How to deploy Django Webapp with subdomain

I have a domain as abc.com. I have created subdomain as xyz.abc.com. I have two Django Webapps both are not same. I want to deploy both Django Webapps with this domain and sub-domain on same VPS server. Webapp deployed on …

11.05.2024
Why won't my home page redirect to a detail view (Django)

So the context is I'm following a tutorial on codemy.com. Somewhere before Django 5.0 I lost my "magic", the tutorial was written for 3.8 or 4.X maybe. I am showing a function based view although I have tried the class …

11.05.2024
Django rest frame-work error : django.core.exceptions.ImproperlyConfigured: Router with basename X is already registered , despite it is not

In my django app am using DRF and it gives me , and it gives me this strange error when i try to run the app : water_maps | router.register(r'breaches_edit_delete', api.BreacEditDeletehViewSet) water_maps | File "/usr/local/lib/python3.10/dist-packages/rest_framework/routers.py", line 59, in register water_maps …

11.05.2024
Composite primary key django and timescaledb (postgresql)

I am using django for my backend and postgresql for my database cause I have timeseries data i use timescaledb. i have hypertable called devices. there is a composite primary key on fields created_datetime(timestamp) and device_id(integer). I want to use …

11.05.2024
How to integrate QR code payment in django

I am facing the issue to integrate QR code in python django website but not getting proper solution Please help me that how can i integrate the QR code payment gateway in django. and what will be the payment method …

11.05.2024
Django products not being added to cart immediately

So I am trying to build a Django e-commerce website, where there is a cart modal which pops up when I try to add any product by clicking the add to cart button. While the product is being added correctly …

11.05.2024
Streaming LLM output in Django

Im planning to develop Django framework for the LLM fine-tuned model based on HuggingFace models, I want the text to be streamed from model to the Django. My issue is that model streams the output in the terminal but not …

11.05.2024
Why no pip packages accessible from any new directory wheras it is accessible from existing directories while in venv

I am working on a Django project. Recently while working on my new project, I had to delete py an open project folder. Now I am not able to access the list of pip packages from any of the newly …

11.05.2024
Django form with MediumEditor not honoring required attribute

In Django, I have a TextField called 'description' in a model with null and blank set to False (for server side and client side validation). I'm using forms.ModelForm to pull the field and I'm using forms.Textarea to assign attributes. In …

11.05.2024
Trying to integrate TinyMCE into django but TinyMCE editor is not showing up

I'm following along sentdex's django development tutorial. This is the code in the admin.py file class TutorialAdmin(admin.ModelAdmin): fieldsets = [ (&quot;Title/date&quot;, {&quot;fields&quot;: [&quot;tutorial_title&quot;, &quot;tutorial_published&quot;]}), (&quot;Content&quot;, {&quot;fields&quot;: [&quot;tutorial_content&quot;]}) ] formfield_overrides = { models.TextField: {'widget': TinyMCE()} } admin.site.register(Tutorial, TutorialAdmin) <a href="https://i.sstatic.net/bmfHmxsU.png" …

11.05.2024
Django rest framework's ModelSerializer missing user_id field causing KeyError

My ModelSerializer is getting a KeyError when I call .data on the serializer and I'm not sure how to properly fix this error. Knox's AuthToken model looks like this class AuthToken(models.Model): objects = AuthTokenManager() digest = models.CharField( …

11.05.2024
Optimizing Django/Postgres Query Performance: Filtering Many to Many relationship using Count Slows Down with Large Dataset

I do have such a model with class RecipeTag(models.Model): tag = models.CharField(max_length=300, blank=True, null=True, default=None, db_index=True) recipes = models.ManyToManyField(Recipe, blank=True) description = models.TextField(blank=True, null=True, default=None) language_code = models.CharField( max_length=5, choices=[(lang[0], lang[1]) for lang in settings.LANGUAGES], default='en', db_index=True # Index added …

11.05.2024
Django - Editing/updating records on formset triggering duplicate error

In Django, I have this FBV that updates selected records: def edit_selected_accountsplan(request): selected_items_str = request.GET.get('items', '') selected_items = [int(item) for item in selected_items_str.split(',') if item.isdigit()] accountsplan_to_edit = AccountsPlan.objects.filter(id__in=selected_items) AccountsPlanFormSet = formset_factory(form=AccountsPlanForm, extra=0) if request.method == 'POST': formset = AccountsPlanFormSet(request.POST) if …

10.05.2024
Getting ModuleNotFoundError: No module named 'django' while deploying Django on uWSGI server, while uWSGI server is running on Cygwin on Windows OS

I have installed Cygwin on Windows 10 and installed following packages gcc-core (version 11.0.4-1, under Devel category ) gcc-g++ (version 11.0.4-1, under Devel category ) libintl-devel (version 0.22.4-1, under Text category ) gettext-devel (version 0.22.4-1, under Text category ) …

10.05.2024
Quelle est le meilleur programmation pour une plateforme de protection de données [closed]

Je suis sur le point de réaliser une plateforme de protection et je demande la plus adéquate programmation pour réaliser ce plateforme je ne suis qu'au tout début qui est le cahier de charge et le plan mais je saiqs …

10.05.2024
Django CMS placeholder на внутрених страницах приложений

СОбственно вопрос в теме. Как сделать так чтобы на страницах приложений был свой placeholder, а не родительской страницы приложения?

10.05.2024
Static files path generated incorrectly in Django project

Description: In my Django project, the static files path is generated incorrectly, appending the current page URL before the static URL. For example, when I'm on the about page, the path becomes http://127.0.0.1:8000/about/static/images/bg/17.jpg instead of <a href="http://127.0.0.1:8000/static/images/bg/17.jpg" …

10.05.2024
Nginx + React + Django: Understanding CORS Request Headers

I'm hosting a React frontend app and Django backend API on Nginx in a single local Raspberry Pi, on ports 80 and 8000, respectively, with the following config: // REACT APP server { listen 80; listen [::]:80; root /link-to/build; index …

10.05.2024
How to post image and text in React Js form?

Here i have two component Child Component which passes text and image to the Parent component and Parent post the form But text is passed but image is getting error. I am using Django as Backend I can provide it …

10.05.2024
Forbidden (CSRF cookie not set.) when trying to connect from a desktop app

I'm developing a desktop application where users can log in using credentials from my Django website's database. The goal is for users to be able to create posts on the Django website (forum) through the desktop application. In the desktop …

10.05.2024
Pipenv skipped update of package, Django 4.2 -> 5

I am trying to update from Django 4.2.13 to the most recent version (Django 5.0.6 at the time of writing). I ran pipenv update and a number of other dependencies were upgraded successfully, as reflected in my Pipfile.lock. However, Django …

10.05.2024
Django-Oscar / Can't subscrive templates from costumer folder

I'm using django and oscar to create an ecommerce site. I'm trying to add allauth, and i need to add buttons to login_registration.html template. I set the templates dir to my custom template folder and already subscrived the oscar/base.html template …

10.05.2024
Problem facing to fetch data from prayer time api in Django App

I am trying to fetch data from this app http://api.aladhan.com/v1/calendarByCity/:year/:month search by city but failed I am writing this code in my project. Can you please help me how to fix this problem? def index(request): if request.method …

10.05.2024
Problem on django queryset and distinct/order with annotated fields

Can anybody help with this problem on django queryset distinct/order with annotated fields? THIS WORKS It returns nicely and called my Serializer after, no problem at all. def get_queryset(self) -&gt; list: distinct_by = ('distance_to_first_point', 'id') pnt = create_point(float(lat), float(lng)) queryset …

10.05.2024
What database should I use? [closed]

I am doing first steps in Django. And I want to write program which can help me in my сurrent work. What is the problem? I need to have fields with dictionary of objects. But I do not know how …

10.05.2024
Django-allauth cant select providers using administration page

I'm trying to add google authentication to my django application that is a social network, I added 'allauth.socialaccount.providers.google' into installed apps and created SOCIALACCOUNT_PROVIDERS = { 'google': { 'SCOPE': [ 'profile', 'email', ], 'AUTH_PARAMS': { 'access_type': 'online', } }, } …

10.05.2024
Save an image to media in post method django

I want to store an image in the media folder and the URL in the image field of the model. in this code the image is directly get saved to the model class CustomUser(AbstractUser): email = models.CharField(max_length=50,unique=True, null=True) username = …

10.05.2024
Can't pass instance while creating an DB entry in django

I have two models, DocumentData &amp; RecurringInvoice, which have a one to one relationship with each other. When I create an entry in the RecurringInvoice table, I want to pass in the DocumentData instance, instead of the id. But I …

10.05.2024
LDAP Authentication with Django Rest Framework

I am new to Django and i am using Django Rest Framework for Backend. I followed this tutorial to add Ldap authenrication to my Django Rest Framework project. AUTH_LDAP_SERVER_URI = &quot;ip&quot; AUTH_LDAP_BIND_DN = &quot;dn&quot; AUTH_LDAP_BIND_PASSWORD = &quot;password&quot; …

10.05.2024
Html dropdown subject list filter

Me working on python django school LMS project and facing issue in html dropdown filter. there are 3 fields. teacher name, subject list, and checkbox of classes. If I select class 1 one then that time subject dropdown should be …

10.05.2024
Django - Request Header Fields Too Large

We use an OAuth2-Proxy for our apps. Therefore the request header includes all groups of a user and the header get large. This is no problem for our fastAPI based apps but not for Django based apps. We always get …

10.05.2024
Django File Upload Not Working: Files Not Appearing in Media Directory or Database

I am developing a Django application where users can upload files associated with specific topics and submissions. Despite setting up everything according to the Django documentation, the files do not appear in the specified media directory or in the database …

10.05.2024
Wanted to build a cloud service where a static file is accessible on every dynamically generated URL

I aim to access specific static files and HTML pages stored in either an S3 bucket or an Azure blob container using various URLs. The concept involves our server generating dynamic URLs in a specific format and then responding with …

10.05.2024
Cryptography Fernet Invalid Token

I am trying in Python Django to create a system for encrypting and decrypting messages. Does anyone know why I get an error every time I try to read a message: &quot;The encrypted message is invalid and cannot be decrypted&quot;. …

10.05.2024
Trouble in setting up virtual environment for django in device

After running installation command, the output are as follows. please help me in setting up virtual env for django \Django&gt;pip install virtualenv Requirement already satisfied: virtualenv in c:\python311\lib\site-packages (20.26.1) Requirement already satisfied: distlib&lt;1,&gt;=0.3.7 in c:\python311\lib\site-packages (from virtualenv) (0.3.8) Requirement already …

10.05.2024
Django Test - How to work out why not redirecting

I have the following Django Test for a CreateView: def test_post_non_chargeable(self): self.client.force_login(self.user) form = EditStudyForm(data=self.non_chargeable_payload) self.assertTrue(form.is_valid()) response = self.client.post(self.url, self.non_chargeable_payload) self.assertRedirects(response, reverse(&quot;researcher_ui:console_study&quot;, kwargs={&quot;pk&quot;: self.study.pk})) The first test, that the form is valid works. The second test doesn't work. The …

10.05.2024
Django serializer is not validating or saving data

I am trying to save data in the database, it works for most of my models but for few models I am not sure why but django is not serializing data. I hope someone can point out where I might …