Django and Python "Questions and answers", page 1568

06.08.2021
Django CookieCutter: django.db.utils.OperationalError: fe_sendauth: no password supplied

How to fix the fe_sendauth: no password supplied erorr? There's this open-source framework for Django that is production-ready (https://github.com/pydanny/cookiecutter-django) I don't exactly know the cause of the error, but I do have some ideas, and I'm going …

06.08.2021
Django forms don't are saving any information

So I have been trying do build a manager of activities with django and I'm still on the scratch. I was trying to test if the code can simply show if a acitivity is done or not, but it don't …

06.08.2021
Picking up broker_api from Django settings

I have a Django / Celery / Flower setup routing messages to RabbitMQ on windows. All works well except that I can't find a way to pick up the flower broker_api from the Django settings file. CELERY_BROKER_URL is picked up …

06.08.2021
Travis selenium does't work - django - stripe - javascript redirection

I have a selenium test that work on my local machine. Creating test database for alias 'default'... System check identified no issues (0 silenced). ............. ---------------------------------------------------------------------- Ran 13 tests in 32.510s OK Destroying test database for alias 'default'... …

06.08.2021
Ability to have users add/edit/remove form fields dynamically?

I am working on a project that requires a base form + template for ever user, based off of a simple model as such... class FloorPlan(models.Model): user = models.ForeignKey(account) stories = models.IntegerField() bathrooms = models.IntegerField() sqft = models.IntegerField() I …

06.08.2021
How to ran a function some time after the user enterd the url? Django

I have a page that 10 seconds after the user enterd a change to the database is made, how do i do that? I need to add this idea to both a class based view and a regular view.

06.08.2021
DRF nested through model serialization filtering

Each of my models is inherited from the base model, which contains the publishing_status field that helps me control whether or not the object is included in the returned data. class BaseModel(models.Model): class PublishingStatus(models.TextChoices): ACCEPTED = 'accepted', 'Accepted' REJECTED …

06.08.2021
Programmatically trigger password reset in Django 3.2

The method detailed here no longer works. Importing django.contrib.auth.forms.PasswordResetForm results in the custom user class not being available (django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'accounts.CustomUser' that has not been installed). How do I send these emails programmatically? To avoid the …

06.08.2021
Django Elastic serach deleting some documents when pointing multiple documents to the same index

I have my django application where i am using django_elasticsearch_dsl to index document to later do elastic search with them. I have two similar models in database so i want the documents to be pointing to the same index in …

06.08.2021
How to get all values from a Model instance on django

I'm using django signals with post_save and receiving an instance: @receiver(post_save, sender=ServiceOrder) def service_order_post_save(sender, instance, created, **kwargs): if created: print(instance) I just want to get all values from this instance without doing field per field (is a big Model). …

06.08.2021
How can I setup multiple Django Apps using Supervisor (including Gunicorn and Nginx)? bind() to [::]:8090 failed (98: Address already in use)

I already deployed a Django/Wagtail App using Supervisor, Gunicorn and Nginx (on Debian Buster), so I can reach it with http://xx.xxx.xxx.xxx:8090. /etc/nginx/sites-available/cms server { server_name xx.xxx.xxx.xxx; listen 8090; listen [::]:8090 ipv6only=on; error_log /home/www.mysite.com/.local/share/virtualenvs/cms-WqsZ9qOt/var/log/gunicorn-error.log; access_log /home/www.mysite.com/.local/share/virtualenvs/cms-WqsZ9qOt/var/log/gunicorn-access.log; location = …

06.08.2021
Getting error when trying run test "RuntimeError" Database access not allowed

I am facing below error ERROR: Database access does not allow def send_orders(): for order in Order.objects.all(): order.send() order.sent = True #factories.py class OrderFactory(....): amount = 100 sent = False #test_order.py def test_send_orders(order): send_orders() assert order.sent

06.08.2021
Django get current model id after model form save & redirect it with this pk to set as fk to another models fk in model form

Working on Django 3.2 & unable to save forms with reference to each other. Like Project>Photos>Assignments>Students every form is a model form & has a relationship with each other. I have one Project Model & Another is Photos, want to …

06.08.2021
Display Image in HTML from SSH with django

I'm trying to display a randomly fetched image via ssh-connection on an HTML page with Django. Currently, I save a temporary image and then display it in the HTML, but this doesn't seem to be necessary or right. views.py: …

06.08.2021
Django allauth. Регистрация и восстановление пароля с использованием email

Получаю вот такую ошибку: TimeoutError: [WinError 10060] Попытка установить соединение была безуспешной, т.к. от другого компьютера за требуемое время не получен нужный отклик, или было разорвано уже установленное соединение из-за неверного отклика уже подключенного компьютера [06/Aug/2021 22:48:01,389] - Broken pipe …

06.08.2021
Can I use google social token to send email through gmail? Django app

I have a django app where I implementeed a method to sign-up through gmail authentication. Now I would like to allow users to send emails using my app through their gmail account. If a user signs-up with Gmail I have …

06.08.2021
How to style ModelForm Choicefield in Django?

I'm trying to style the ChoiceField options for the Medicines in a prescription ModelForm to be in this format: <select> <option value="">Select a Medicine</option> <optgroup label="Favorite Medicines"> <option value="First">Brufen - Abbott - 600 Mg - Tablets</option> </optgroup> <optgroup label="Other"> <option …

06.08.2021
Deploying Django application To AWS ElasticBeanstalk

I am trying to deploy a django application to AWS ElasticBeanstalk. I am working on a Linux machine. It all goes well but when deployment is done I get "502 Gateway Error". From a deep search I found that people …

06.08.2021
Docker ModuleNotFoundError: No module named 'xhtml2pdf'

I've looked through several websites but I can't seem to find an answer. I'm new to django and docker and whilist building my first project which is a quotation generator, I've been looking for different ways to generate a pdf …

06.08.2021
JS files not updating in python dev server

I am running a local development server with python using VS as ide through python manage.py runserver. When I update and save JS files, the views in browser do not update (even restarting the server and PC). I refreshed the …

06.08.2021
Django how to update boolean value of an objects in class based views?

In function based views I am using this code Notifications.objects.filter(receiver=user, is_seen=False).update(is_seen=True) for update an objects status from False to True. How to do that in class based view: here is my code: class ListNoti(ListView): model = Notifications template_name = 'notifications/notifications.html' …

06.08.2021
Django rest framework invert serializers

In Django, I have in models.py models defined like this : class foo1(models.Model): name = models.CharField(max_length=100) class foo2(models.Model): name = models.CharField(max_length=100) .... foo1 = models.ForeignKey(foo1, on_delete=models.SET_NULL, null=True) class foo3(models.Model): name = models.CharField(max_length=100) .... foo2 = models.ForeignKey(foo2, on_delete=models.SET_NULL, null=True) …

06.08.2021
How can I retrieve a specific JSON data

I want to retrieve a specific data after selecting an option form. When I select I got data in JSON format which I can't separated. I have tried obj.purchase_price but got undefined. my following code provide following data [{"model": …

06.08.2021
ModuleNotFoundError: No module named 'spyder'

I want to use a crawler project inside Django. I've set up celery and beats correctly but when I use the scraper project inside a Django app gives me the error ModuleNotFound even if I have added it to the …

06.08.2021
Django download file using CBV

How to use Class Based Views eg. TemplateView to display Django template with download links? Clicking the link should start downloading selected file. I already know how to do it with Function Based Views. Also - is it good idea …

06.08.2021
Why Django favicon reloads on routing pages? (about SSR)

Hi I'm using Django framework and made a simple web application. But on routing each page, I could see favicon reloads (OR maybe it could be loading html file). So here's the question. Is it correct that favicon reloads …

06.08.2021
Django-rest-passwordreset create and send token manually

Reading the [django-rest-passwordreset][1] I have not found a way to create and send the reset_password_token manually, meaning without the use of the endpoint created by the package. Currently I have this implementation: urlpatterns = [ ... url(r'^api/password_reset/', include('django_rest_passwordreset.urls', namespace='password_reset')), ... …

06.08.2021
How do I change a model after I ran makemigrations and migrate? Django

I made a model ran all the neccesery migrations commands and I want to add a field and change a field. How do i do that? I thought about changing them in models.py and ran makemigrations and migrate again but …

06.08.2021
Python can't see environment variables from script

I was invited to collaborate on a Django project and now I need to set it up. I am stuck with setting environment variables. In the given project envparse is used. I was provided an .env file, where items look …

06.08.2021
Import "pyrebase" could not be resolve pylance(reportMissingImports)

Installed pyrebase4 in my system but still unable to import in my view.py even tried "import pyrebase4" still the same error, I followed a youtube tutorial for it I followed the exact same things he/she said, so I'm not understanding …

06.08.2021
In Django raw query selects all my user twice

I have a raw query in my view: SELECT stressz_profile.id, projekt_id, user_name_id, szerv01b AS szervkult01a FROM stressz_szervezetikultura INNER JOIN stressz_profile WHERE stressz_profile.projekt_id=1 I try to get the data from the db but every time it duplicates the results. It …

06.08.2021
Error when installing node-django-hashers

In order to implement password hashing on the server side with nodeJS 14.7.4, we selected node-django-hashers so that it can be implemented the same with django website side, but when installing module, we are recieving the following error. docker …

06.08.2021
Single search bar managing all fields using django-filter and django-tables2 through Jquery

I need to manage the django-table2 using django-filter through jquery. Please help me how can i access this via jquery and how do i pass queryset in django-filter I am having my search box in the following way: where I …

06.08.2021
Return context variable along with saved form

I have following class based view which creates a project using form and then returns that created form. class ProjectCreateView(LoginRequiredMixin, CreateView): login_url = "registration:login" model = Project # fields = ['name', 'desc', 'start_date', 'end_date'] template_name = 'project/form.html' form_class = ProjectModelForm …

06.08.2021
'verbose_name': _('Small screens') NameError: name '_' is not defined

After installation django-responsive2 as django-responsive2, i got following error: 'verbose_name': _('Small screens') NameError: name '_' is not defined I use from django.utils.translation import gettext_lazy as _. I got this error: mw_instance = middleware(adapted_handler) TypeError: object() takes …

06.08.2021
Converting my Django/Python app from App Engine Standard Environment to Flexible Environment

I am trying to convert my Django/Python app from the Google App Engine Standard Environment to the Flexible environment mainly due to the app becoming slow and was constantly hitting a soft memory limit and suggested I upgrade to a …

06.08.2021
Редирект на прошлую страницу при сохранении объекта

Есть ли стандартный или просто способ редиректить пользователя из админки на прошлую страницу (с которой он пришел на страницу сохранения объекта)?

06.08.2021
How i can wrap json response data for djago-rest-framework?

I use djano rest framework. I have model, serializer and view: class PictureModel(models.Model): id = models.AutoField(primary_key=True) url = models.CharField(max_length=256) class PictureView(mixins.ListModelMixin, generics.GenericAPIView): serializer_class = PictureSerializer queryset = PictureModel.objects.all() def get(self, request): return self.list(request) class PictureSerializer(serializers.ModelSerializer): class Meta: model = PictureModel …

06.08.2021
How to make a web app with an embedded interactive map?

I work on a project where I have to make a web app. The main idea is for the app to have a map (from OSM preferably) on which you can draw a rectangle and then get lon and lat …

06.08.2021
How to retrieve list of tasks in a queue in Celery on Heroku?

My goal is to retrieve active & reserved tasks on my Celery workers. I'm using a Django-Celery-Redis framework. As suggested here: Retrieve list of tasks in a queue in Celery I have done this to retrieve the tasks: from …