Django and Python "Questions and answers", page 1590

07.08.2021
How to set Heroku profile so it accepts "yes" in any terminal question for Heroku Deployment

I am trying to run a command while deploying my Django code to Heroku. I want to accept any question it might get in terminal. I tried to add following to the procfile, but it didn't work. release: python manage.py …

07.08.2021
Facing troubles on bringing the Django admin user tools like welcome, view site, log out on the custom template

I have to override the blocks like branding,site_title, and index title to a custom template. But the user tools are not displaying. How I get. How I want. <a href="https://i.stack.imgur.com/bMqYX.png" …

07.08.2021
DateField in Django Forms shows like simple text input

My Form : date = forms.DateField(widget=forms.DateInput(attrs={'class': 'form-control'})) My HTML : &lt;label class=&quot;form-label&quot;&gt;Date&lt;/label&gt; {{ form.date }} &lt;div class=&quot;invalid-feedback&quot;&gt; Enter Date &lt;/div&gt; Also I don't want to add type &quot;date&quot; in my forms. Issue picture : enter …

07.08.2021
How to configure a django url correctly in javascript

I have seen lots of questions and answers on this topic, but the solution seems to evade me. common/urls.py path('use-selected/&lt;str:app_base&gt;/&lt;str:board_number&gt;/', views.UseSelectedItem.as_view(), name='use-selected'), If I enter the the following code in my template, it works correctly &lt;a id=&quot;use-selected&quot; href=&quot;{% url …

07.08.2021
Django Paginator. How to set number of pages or elements of list

I need to create a Paginator object for function based view. When I send a request to googleapi I receive json with totalItems and items keys. GoogleApi paginates request to 10 items. Let's say the totalItems is 800 so I …

07.08.2021
Creating an Django API end point for data with foreign key value

First time asking question will try and make it clear what I'm trying to do. I have 2 models called Configuration and Results. class Configuration(models.Model): title = models.CharField(max_length=50, default=&quot;&quot;) houseType = models.CharField(max_length=50) numberOfHouses = models.CharField(max_length=50) maxAmpere = models.CharField(max_length=50) date = …

07.08.2021
Create a timer in the Django admin model

I want to create a timer in such a way that when the time is set in the admin model, the timer will be activated. Thank you if anyone knows. enter image description here

07.08.2021
Не запускается Docker container

Не запускается Docker когда использую entrypoint.sh Выдает ошибку ERROR: for debt_web_1 Cannot start service web: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: &quot;usr/src/app/entrypoint.sh&quot;: stat usr/src/app/entrypoint.sh: no such file or directory: unknown ERROR: for web Cannot start …

07.08.2021
DJango admin base_site template extension not working

I am trying to override the basic structure of a Django admin page using the below code: {% extends &quot;admin/base_site.html&quot; %} But the problem is, using this I only get the branding of the site, everything else like the …

07.08.2021
Connecting to AWS RDS Postgres Instance from my Django Project (Settings.py)

Settings.py import os import dj_database_url ... DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': os.environ.get('DB_NAME'), 'USER': os.environ.get('DB_USERNAME'), 'PASSWORD': os.environ.get('DB_PASSWORD'), 'HOST': os.environ.get('DB_HOST'), 'PORT': 5432 } DATABASES['default'] = dj_database_url.config(os.environ.get('DATABASE_URL'),conn_max_age=600) I have a environment variable in my machine postgres://&lt;user&gt;:&lt;password&gt;@&lt;host&gt;:5432/cust_manage this …

07.08.2021
Hide algorithm, iterations, salt in django password field

In django user table password are encrypted automatically with a secure algorithm (pbkdf2_sha256) with salt and iterations. But what I don't understand is why the django password field shows the algorithm, iterations and salt in this format: &lt;algorithm&gt;$&lt;iterations&gt;$&lt;salt&gt;$&lt;hash&gt; I thought …

07.08.2021
Login form not initializing not authenticating

When I was adding a template from the internet to my login.html code I encountered a problem. When I try to login it did not work. Even after I added CSRF tokens and login form control code. It has a …

07.08.2021
Django | Queryset ManyToMany Relation through Instance

I would like to display the different dates for each course. A course can also have several dates. Unfortunately I can't find a solution. Models: class Course(models.Model): course_number = models.CharField(max_length=24, blank=True) course_location = models.ForeignKey(Course_location, on_delete=models.CASCADE) course_dates = models.ManyToManyField('Course_dates', through=&quot;Course_Course_dates&quot;) def …

07.08.2021
Контроллеры-функции или контроллеры-классов django

Есть вопрос, в каких случаях используют контроллеры-функции, а в каких контроллеры-классов в django?

07.08.2021
Request data empty with formData - Django Rest Framework

I am trying to save strings, floats and an image via a POST request made to a Django Rest Framework backend: # My view: class CreatePost(APIView): # tried with and without parser: # parser_classes = [FormParser, MultiPartParser] def …

07.08.2021
Django, all views require login except `@login_not_required` decoratored views

Django is centered towards allow access to all the majority of the time, and restricting acces on the exception. I am making a site whereby I would like access restricted the most of the time, and the rare case is …

07.08.2021
Using Django's GenericForeignKey with Async Graphene Subscription

I've implemented graphql_ws to subscribe to updates from a Notification model that uses multiple GenericForeignKeys. My setup works well, except when I try to query information from those foreign objects. I then get the following error: graphql.error.located_error.GraphQLLocatedError: …

07.08.2021
"Incorrect type. Expected pk value, received User."

I have these two models: order and route. The route has a oneToMany relation with Order as you can see: class Order(models.Model): customer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='customer') retailer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='retailer') date_publish = models.DateField(default=datetime.date.today) date_available = models.DateField() weight = …

07.08.2021
Django Ajax Post - works sometimes

I have a Django application where I am using AJAX to do a post when submitting a form. My issue is what do I set the URL to in my JavaScript? JavaScript snippet: $.ajax({ url: &quot;search/do_post/&quot;, // the endpoint …

07.08.2021
How to upload a saved file in django

In my case, the user gives a word in the front-end and in the back-end, i will call some function that i wrote and at the end i will build a .PDF file in the /media/reports directory. how i can …

07.08.2021
Django_elasticsearch_dsl -RequestError(400, 'search_phase_execution_exception', 'failed to create query: For input string: )

I am trying to search with Elasticsearch using django_elasticsearch_dsl and 'django_elasticsearch_dsl_drf',, but I get RequestError(400, 'search_phase_execution_exception', 'failed to create query: For input string: &quot;MM&quot;'). I am able to search if my input is an integer or a float , but …

07.08.2021
How to sync django calendar project with mobile app calendar?

I have created a calendar with drf and react js which has all calendar features including events. Now, I'm trying to see my calendars and events on mobile calendar apps like Samsung or iphone calendar. I use google to authenticate …

07.08.2021
Python/Django 'WindowsPath' Type Error in Django Rest Framework (DRF)

I keep getting the 'TypeError' below when running a Django project in the virtual environment. What could be the problem? Thanks in advance! File &quot;D:\Studio\Python\REST\elections\env\lib\site-packages\django\db\backends\sqlite3\base.py&quot;, line 190, in close if not self.is_in_memory_db(): File &quot;D:\Studio\Python\REST\elections\env\lib\site-packages\django\db\backends\sqlite3\base.py&quot;, line 287, in is_in_memory_db return …

07.08.2021
Get input to translate a web page django

I'm trying to use multi language for my website by default its language is english , but i 've to add arabic and kurdish(arabic character) to the website ,i want to get input from the user to translate the website …

07.08.2021
Have a constant parameter in all my django URLs

I have a django website that shows data which is seperated in 3 differents databases corresponding to different servers. I have a dropdown list on my website that allow to choose the desired server. What i would like …

07.08.2021
Create serializer fields according to the data in Django Rest

I am writing an api for Auth. and I have 2 user types ( Donors , Charity ) when they did registration my data is changing. So that I need to update my fields according to the data. Here is …

07.08.2021
Unable to deploy django project on heroku

I am trying to deploy a Django project on Heroku but I am getting the following error. 2021-08-07T10:05:35.789899+00:00 heroku[router]: at=error code=H10 desc=&quot;App crashed&quot; method=GET path=&quot;/&quot; host=betabrains.herokuapp.com request_id=2e0f8a7e-ce6f-492b-88d9-81b89a3d7ec0 fwd=&quot;223.187.110.102&quot; dyno= connect= service= status=503 bytes= protocol=https 2021-08-07T10:05:36.294818+00:00 heroku[router]: at=error code=H10 desc=&quot;App crashed&quot; …

07.08.2021
How to return articles from followed users only?

Right now i am successfully able to return every article without issue. But what i want to do is this: I want to return the articles,only followed by the current authenticated user. How can i do it? models.py class User(AbstractUser,PermissionsMixin): …

07.08.2021
Django create views use more models

Hi everyone I have a doubt with the use of forms and models. I have to create a code that creates records in multiple tables and I don't know how to do it. my goal is to create a page …

07.08.2021
Python/Django 'DEFAULT_PERMISSION_CLASSES' Syntax Error

I'm trying to get my Django project up and running but keep getting the error below when I run the code in the virtual environment. What could be the problem? Thanks! Traceback (most recent call last): File &quot;D:\Studio\Python\REST\elections\manage.py&quot;, line …

07.08.2021
How can I display the image to the desired product category? (if there are two separate models (Product and Image))

I can't figure out how to connect two models (product and images) in views and output images in html. At the moment, several images are loaded for a specific project (for example, photos of a 3D model) all this through …

07.08.2021
Django Rest Framework: Register pure function-based views with router so it appears under API root

This is my views.py: class ChoicesViewSet(viewsets.ModelViewSet): queryset = SingleChoice.objects.all() serializer_class = SingleChoiceSerializer ... class AssessmentTakersViewSet(viewsets.ModelViewSet): queryset = AssessmentTaker.objects.all() serializer_class = AssessmentTakersSerializer ... @api_view(['POST']) @parser_classes((JSONParser,)) def studio_create_view(request, format=None): &quot;&quot;&quot;&quot; A view that accept POST request with JSON content and in turn …

07.08.2021
I want to do something on value of a ModelForm before saving in database-django

I'm trying to do something on the value of a ModelForm in Django before saving that on the database. that &quot;something&quot; is changing the value of the DateTime field... I want to take Jalali DateTime from the user in the …

07.08.2021
Is there any way to clear the session on a browser or tab close in Django as SESSION_EXPIRE_AT_BROWSER_CLOSE = True is not working at all?

When I close a tab or browser and then I run the application again opening the browser again, the previous session remains active. I tried SESSION_EXPIRE_AT_BROWSER_CLOSE = True in settings.py file in the project directory as per the Django documentation. …

07.08.2021
Bidirectional one-to-may django

I would like to create a bidirectional one-to-many and many-to-one relationship in django like: class User(models.Model): device = dont_know_what_to_write() class Device(models.Model): user = models.ForeignKey( User, on_delete = models.CASCADE ) What should I do?

07.08.2021
Django makemigrations does not create admin databases

I have a django project, this is the installed apps entry in settings.py: INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'crawler', ] when I run python manage.py migrate everything seems to be fine. But when I try …

07.08.2021
In Visual Studio Code, how can i trigger intellisense in an html django template file to get parameters from a .py file under same app?

I'm learning Django and I would like to know if there's a way to trigger intellisense within an html django template file to get a parameter declared in a python class from another file under the same app, I'm trying …

07.08.2021
Jango filter by latest date in python

I have the following model class CoinsQuotes(models.Model): coinQuotesID = models.AutoField(primary_key=True) coinID = models.ForeignKey(Coins, on_delete=models.CASCADE) coinCurrency= models.CharField(max_length=10) coinPrice = models.DecimalField(decimal_places=8, max_digits=40) coinVolume24h = models.DecimalField(decimal_places=2, max_digits=30) coinPercentageChange1h = models.DecimalField(decimal_places=2, max_digits=20) coinPercentageChange24h = models.DecimalField(decimal_places=2, max_digits=20) coinPercentageChange7D = models.DecimalField(decimal_places=2, max_digits=20) coinPercentageChange30D = models.DecimalField(decimal_places=2, max_digits=20) …

07.08.2021
Concurrency Tests in Django

Just started Django last month. I needed help running concurrency tests in Django, so what I've done is tried to write code that will prevent issues that arise due to lack of concurrency but what I don't know is how …

07.08.2021
Using Arabic letters in Django urls causes a 404 error

I want to use Arabic letters in my addresses, there is no problem in local mode, but it causes an error on the server. models.py class Product(models.Model): title = models.CharField(max_length=40, verbose_name='عنوان محصول') slug = models.SlugField(max_length=100,unique=True,allow_unicode=True, verbose_name='آدرس') urls.py urlpatterns = …