Django and Python "Questions and answers", page 1625

10.08.2021
Django Selenium on FreeBSD Exec format error geckodriver / chromedriver

I am trying to use selenium on django server (hosting with ssh, user permission). Os: FreeBSD 12.2-RELEASE amd64 display = Display(visible=False, size=(1325, 744)) display.start() opts = Options() opts.add_argument('--headless') import os path = os.path.abspath(os.getcwd()) driver = webdriver.Firefox(executable_path =path+"/geckodriver", options=opts) The …

10.08.2021
Excluding existed users in the ManyToManyField

I am building a small BlogApp and I build a feature of adding favorite users. User can search and add the user in his favorite users list I am now building a feature if searched user is already in another's …

10.08.2021
Django upload image from form

I got this weird problem. I work with a PostgreSQL database. I made a model and form and migrated it, registered it in admin.py. When I am in the admin panel, I can add data to the form. One of …

10.08.2021
Python/Django 'ImportError: cannot import name 'python_2_unicode_compatible' in Django Rest Framework

I recently updated my DRF app from Django 2.1 to Django 3.1. But I keep receiving the error below when running the app. Before the upgrade the app was working fine. I'm using python version 3.9.0. Thanks in advance! …

10.08.2021
OrderItem matching query does not exist, while trying to add a product to cart

I am trying to add to cart a single product, but i have been encountering a problem and now i am stucked, I have tried different ways, but none of them worked. Please help as I am trying to learn …

10.08.2021
Convert mysql join to django orm

I have few db tables for practice i am converting complex sql queries to django orm queries This is sql code i am stucked in: "SELECT hla.`id`, CASE WHEN hla.`id` IS NULL THEN 'Not enabled' ELSE 'Enabled' END AS scv_user …

10.08.2021
How to fix Collectstatic ERROR in Heroku deployment for React-Django APP

I've been trying to deploy my React/Django app on heroku for a while and I still can't fix the collect static error. I've seen and tried plenty of solutions but none of them seems to cut it for me. The …

10.08.2021
Django UserCreationForm not saving the given data data in the User model

When i hit submit, the signup page just refreshes itself and doesn't save the data in he User model. I confirmed it by visiting the admin site. Urls.py: from django.urls import path, include from . import views urlpatterns = [ …

10.08.2021
Bootstrap carousel wont show images when i run it in django but they load perfectly fine when i use them in a normal HTML file

I used this bootstrap code to insert a carousel in my django website homepage , but the local images just wont load , how ever if i use images from web apis like unsplash they load perfectly fine , or …

10.08.2021
How to return a custom, non model value with serializer in Django?

I'd like to return a custom value from my serializer. I'm getting authentication tokens for the user and would like to return them as part of the registration process. At the moment I'm returning the user object and I don't …

10.08.2021
Add multiple instances via form

I'm trying to create a view that can save me multiple objects of the same type. with the code I wrote below it only creates an object with the data of the last compiled object, leaving out those above form.py …

10.08.2021
Как создать базу данных в PGAdmin? И в дальнейшем вносить изменения в файлы? [закрыт]

В backend'е совсем новичок. По возможности опишите максимально подробно. Заранее Спасибо!

10.08.2021
Downgrade open api version in drf spectacular in django rest framework

I have a project in Django Rest Framework (djangorestframework == 3.12. *) And I am now using drf-spectacular == 0.17.0 and I have an open api version 3.0.3. I need open api version 3.0.1. Tried to do so by downgrading …

10.08.2021
Django UNIQUE constraint failed: accounts_user.username

I am implementing a custom Django user from scratch. Almost all things are working, but an issue arises when I create new user from the Django admin panel as follows. django.db.utils.IntegrityError: UNIQUE constraint failed: accounts_user.username Why does this error …

10.08.2021
Django add object with the current user

I'm trying to create a todoapp with google login to create personal todolist for each users. here's views.py from django.contrib.auth.decorators import login_required @login_required def todoView(request): all_todo_items = Todoitem.objects.filter(userid=request.user.id) return render(request, 'todoapp/home.html', {'all_items': all_todo_items}) def addTodo(request): add_new_item = Todoitem(content=request.POST['content']) add_new_item.save() return …

10.08.2021
Create foreign key from auth_group_permissions table in django

I want to make foreign key from auth_group_permissions table.(the M2M table between permission and group) I know that I can use through, but it isn't appropriate if I make modify in Django library. I used Django guardian …

10.08.2021
Does django encode passwords in the Database?

I created a user with a password password123 but in the database the password field look like this pbkdf2_sha256$260000$rJZWVrYXlokRG8fGMS1fek$S7Dm9soflUsy0Q74CJP8sB60tgfRWuRPdqj5XL0DBV0= the problem: is when I create new user via rest framework i got the poassword feidl look like passsword123 …

10.08.2021
Django queryset time interval

I need to make object selections in my database by time interval currently i found a method to select only objects from a day but not from an interval with this: data.filter(end_at__day=datetime.datetime.now().day) I saw this on the …

10.08.2021
Error in setting up django model and serializer

I am having the following error in DRF ( Django Rest Framework ): Internal Server Error: /book/book/ Traceback (most recent call last): File "/home/divyessh/Desktop/Projects/club-booking/booking-new/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/home/divyessh/Desktop/Projects/club-booking/booking-new/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, …

10.08.2021
Which AWS EC2 hardware options should I use for my project

I developed a django prject which uses social_auth (Google) for logins and when the user logs in to the website, their details (pre-stored in database) will be displayed to them and the user can select an option from a dropdown …

10.08.2021
Why Django model extesion validator doesn't work

I want to only .xlsm files to be uploadable to the form.I tried a lot of thing according to this question. But did not work. I don't know why? How can I solve it? models.py from django.core.validators import FileExtensionValidator …

10.08.2021
How to include Run functionality in my API in Django?

I'm working on Django project where I have to make a API. In my normal Django I have one functionality named Run , that I want to add that functionality in my API View Here's my model class Robot(models.Model): robot …

10.08.2021
How to correctly delete Model object field in django

Hello I want to delete my field : tag_number = models.PositiveIntegerField('Tag number', validators=[ MinValueValidator(1), MaxValueValidator(MAX_TAG_NUMBER), ]) and write fo this method: # @require_POST def book_tag(request, pk): book = get_object_or_404(Book, pk=pk) book.tag_number = **book.tag_number.delete()** book.tag_number = book.generate_tag() book.save() return redirect('book:book-list') …

10.08.2021
Can I write one viewset for List, Retrieve, Update, and Delete?

I am using a viewset.ModelViewSet to list, retrieve, update and delete Car objects. I have two urls: one ends with .as_view({'get': 'list'}) and other with .as_view({'get': 'retrieve'}), and latter one is used for updating and deleting a car object. Is …

10.08.2021
Best practice to compile Django translation files

I am looking for a best practice approach on how to compile translation files in Django. Currently the following is given: GitHub + POEditor Importing into POEditor is done with Webhooks, which works quite fine. Exporting is also done automatically, …

10.08.2021
Using fields from a aggregated QuerySet in a django template

So I got a QuerySet result from an aggregate function to display in a low-spec eBay clone of mine. But my problem is displaying certain fields in the Django template as I want, for example, I want to display the …

10.08.2021
How to obtain custom simpleJWT tokens in views with Django?

I have a custom serializer to get tokens without a password for a user: class ObtainTokensWithoutPasswordSerializer(TokenObtainPairSerializer): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['password'].required = False def validate(self, attrs): attrs.update({'password': ''}) return super(TokenObtainPairWithoutPasswordSerializer, self).validate(attrs) In my views I use it …

10.08.2021
Django web app css not being refreshed in browser

I'm having some issue with a django app and it's CSS file refreshing. Basically I can see that the changes I make in my file are identified and copied in the root folder of my website, however when I open …

10.08.2021
How do I send a file to the Django server via ajax?

I can't figure out for more than a week, I need to send an image to the Django server, but I get the error: 415 (Unsupported Media Type) If I change ContentType to multipart/form-data, I get: 400 (Bad Request) is …

10.08.2021
Want to convert proper JSON request in AXIOS ReactJs to send to django

My payload is in string form as below: payload= "[{"message":"message text", "id":1, "code":0}, {"message":"message text", "id":2, "code":1}, {"message":"message text", "id":3, "code":0}]" I am getting the pay load from query string. ex = https:\xyz.com\endpoint?payload=[{"message":"message text", "id":1, "code":0}, {"message":"message …

10.08.2021
Pip library body_measurements (python)

I want to get the body measurements through an image using pip library body_measurements. Is there any material related to this? I have seen openCV2 library for this thing but that does not my requirement.

10.08.2021
Fetching specific data from SQLite DB to django forms

How do I fetch like specific data I want to a django form. I know how to fetch the entire database to a table by using loops. But I want to fetch specific data according to what user select. At …

10.08.2021
Django multiple radio input from HTML form with same name

I am having a problem with Django forms. I am currently using the request.POST to validate the POST within views. I want to send inputed-data(radio type) from my template with the same name. In my template.py: <form method="post" action="{% url …

10.08.2021
Django Jazzmin add button disappeared after adding mptt admin

I'm using jazzmin for django admin and mptt. After adding mptt to admin, in jazzmin theme add button disappeared. I'm using latest versions of all libraries class CustomMPTTModelAdmin(MPTTModelAdmin): # specify pixel amount for this ModelAdmin only: mptt_level_indent = 30 admin.site.register(Menu, …

10.08.2021
Cannot activate virtualenv via python terminal

I create a virtual environment named djangoenv. I can run it with using cmd but I cannot in python terminal this is cmd picture and this is python terminal picture how can I run …

10.08.2021
Problems in debugging Django projects (Dev branch) in Pycharm

I'm having a problem debugging Django (main/4.0.dev20210730183450) projects in Pycharm (2021 CE) and following is my config I can run (by clicking the run button) the project with no problem; Server runs …

10.08.2021
Please help me on following error with Django and PostgreSQL with docker

My Dockerfile FROM python:3 ENV PYTHONUNBUFFERED=1 WORKDIR /django COPY requirements.txt requirements.txt RUN pip install -r requirements.txt My docker-compose.yml version: '3' services: db: image: postgres volumes: - ./data/db:/var/lib/postgresql/data environment: - POSTGRES_DB=postgres - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres container_name: postgres_db web: build: . …

10.08.2021
Django REST with jwt + regular admin panel

I've setup a basic django app using scaffolding which creates all those nice admin panels for free. I want to expose a REST api so I've followed this tutorial to get it running and add JWT authentication …

10.08.2021
I send any email with website that also show me on my email's sent box

Hello I have 1 question that i want to integrate my outlook with my django website that means if i send any email with website that also show me on my email's sent box. Can anyone help me to do …

10.08.2021
How to set default for the foreignkey when using a form?

Scenario: I want to make an app that has servers(500+) as a model and another model that has posts as a foreign key to the server model to log what we did on each server.So as I said I have …