Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Fabric 3.2.2 asks for sudo password when executing NOPASSWD command
I have configured sudoers to let me execute two commands without password: # Allow foobar restart app_server Cmnd_Alias RESTART = /home/foobar/restart_nginx, /home/foobar/bin/restart_app_server foobar ALL = NOPASSWD : RESTART When I ssh to the server I can execute both commands without password: sudo /home/foobar/bin/restart_app_server sudo /home/foobar/bin/restart_nginx However when I do the same with Fabric I get the following error: sudo /home/foobar/bin/restart_app_server sudo /home/foobar/bin/timers_nginx sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required This is what my fabfile looks like: conn = Connection(local_settings.FABRIC_HOST, port=local_settings.FABRIC_PORT) conn.run( f"sudo /home/foobar/bin/restart_app_server && " f"sudo /home/foobar/bin/timers_nginx", echo=True) I tried shell=False, tried sudo(...) instead of run(...). No difference at all. This issue appeared after updating from Fabric 2.x.x to Fabric 3.x.x. But I can use old Fabric 2.x.x. right now. -
Why does one of these produce an error and the other does not?
I am attempting to run a simple python script to populate my Teams database for my django project under the teams app. The script is reading a list, I have included it below under the error on things i've tried and the results I expected. Mmm-anywaysss, I understand it has something to do with the "python needing to setup DJANGO_SETTINGS_MODULE" ? (.venv) root@firstfiverugbycloud:/home/django/firstfiverugby# python populate_teams.py Traceback (most recent call last): File "/home/django/firstfiverugby/populate_teams.py", line 2, in <module> from teams.models import Team, League File "/home/django/firstfiverugby/teams/models.py", line 3, in <module> class League(models.Model): File "/home/django/firstfiverugby/.venv/lib/python3.10/site-packages/django/db/models/base.py", line 129, in __new__ app_config = apps.get_containing_app_config(module) File "/home/django/firstfiverugby/.venv/lib/python3.10/site-packages/django/apps/registry.py", line 260, in get_containing_app_config self.check_apps_ready() File "/home/django/firstfiverugby/.venv/lib/python3.10/site-packages/django/apps/registry.py", line 137, in check_apps_ready settings.INSTALLED_APPS File "/home/django/firstfiverugby/.venv/lib/python3.10/site-packages/django/conf/__init__.py", line 102, in __getattr__ self._setup(name) File "/home/django/firstfiverugby/.venv/lib/python3.10/site-packages/django/conf/__init__.py", line 82, in _setup raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. (.venv) root@firstfiverugbycloud:/home/django/firstfiverugby# python manage.py shell < populate_teams.py (.venv) root@firstfiverugbycloud:/home/django/firstfiverugby# I am just trying to run a script to populate my database with test teams for a website I am building. The script just imports the models from my django app. # Import the Team model from your Django app from … -
is there a node.js lib/package that allows me to generate an executable python file?
So, I've got this web project in which a user inputs some info to a form and a python file is generated containing that info. What I want to do is send that file to my node.js server so that it transforms it into an executable python file, containing it's dependencies, and sends it back to the user so he can download it. With that said, is there any library/package that allows me to do that with Node.Js? ps: I am also considering using Django instead of Node.Js if it turns out to be too complicated or less efficient than Django. -
Local postgres database not syncing with Heroku postgres database
I am creating a CRM system with Django for my non-profit organisation. Have installed a local postgres database to which I created a table students and have added 2 rows via Django Admin interface. When I display these rows in a CSS table by running the app on localhost, the 2 records are correctly displayed. After migrating and pushing a git commit and then running the Heroku hosted instance of the app. The two records are not visible. localhost heroku instance I have no idea how to push my local updates to the database to the heroku postgres database. Searched around on the internet and have tried resetting the database but to no avail. -
Using Django Template inheritance, how can I have the same code at the bottom of my page?
I have been trying to add a footer to my layout.html, which is inherited by other pages in my Django project. I am looking to have a footer which is permanently at the bottom of any webpage like Stack Overflow does. I envisage this should be most efficiently done through inheritance. My suggestion from layout.html is shown below: HTML: {% block body %} {% endblock %} <div class="test_footer"> Footer Test </div> CSS .test_footer { width: 100%; background-color: var(--primary-colour); padding: 20px; box-sizing: border-box; position: absolute; bottom: 0; } The problem I have is that test_footer does not show beneath the rest of my body content. Instead it shows at the bottom of the browser covering html shown by the body and then moves up when I scroll. -
how to get parent and children in Django Models
I'm new to Django and I wanted to ask a simple question. let's take example model: class Model(models.Model): name = models.CharField(max_length=30) parent = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True) with that model let's create a few objects. indentation means that the parent is specified e.g. test5 have object test3 as a parent. test test2 test4 test3 test5 test6 so now my question. is there a way to get children of an object, parent of an object and nad objects without parents specified? I've tried to work it out with filters but unfortunately, i didn't managed to figure out how to do it -
How to turn on exceptions for an invalid dictionary lookup in Django templates?
When the Django template system encounters an invalid dictionary lookup it silently replaced by an empty string. For specific dictionary lookups though, I'd like Django to raise an exception to help with debugging. Assuming a dictionary like this: colors = {"red": 1, "green 2, "blue": 3} An exception should be raised here: {{ colors.orange }} How can I force the Django template system to raise an exception when it encounters an invalid dictionary lookup? -
Django-allauth best practices
Just trying to look for some help on best practices for using Django-allauth and implementing it into a project. First, where should Django-allauth be located? I have it in my virtual environment, which is outside of my Django project. Should I create an app and then install it into that app (which would be located in the project) or is it perfectly fine where it is now? I am trying to make it easier for implementing updates or making changes, etc. Second, where should the virtual environment be located? As previously stated, I have it located outside of the Django project folder. Is that fine and makes sense? Lastly, is there anyway to change the table names for Django-allauth? Would it make sense to change the default on how Django names tables in a database? Thanks for your help! -
How can I customize Authentication in Django rest framework because data source for django is External API not any traditional database
I am trying to authenticate user in django but user details are in elasticsearch. In this project we are not using any traditional database. Our requirement is that if user sends a request to DRF API for login with username and password we have to fetch the data from elasticsearch and verify the username and password and if it is correct user is authenticated. After that If I try to access any Protected API I have to send these credentials in every request I am not able to get how can I implement session in that case so that after login a session will be created and used to authenticate if user is trying to access protected APIs. I have created custom authentication method: from rest_framework.authentication import BaseAuthentication from rest_framework.exceptions import AuthenticationFailed from myapp.elastic_helper import ElasticsearchClient class ElasticsearchAuthentication(BaseAuthentication): def authenticate(self, request): username = request.data.get('username') password = request.data.get('password') if not username or not password: raise AuthenticationFailed('Login is required') response = ElasticsearchClient().get_user_from_elasticsearch(username=username) if response['hits']['total']['value'] != 1: raise AuthenticationFailed('Invalid username or password') user_data = response['hits']['hits'][0]['_source'] if user_data.get('password') != password: raise AuthenticationFailed('Invalid password') user = CustomUser(username, user_data) request.session['username'] = username return user, user_data class CustomUser: def __init__(self, username, user_data): self.username = username self.user_data = … -
ModuleNotFoundError: No module named 'wtools2'
I am trying to run my Django Application, getting following error when using this command Line. python manage.py runserver Error (venv) F:\ATSG\FrontEnd\wtoolgui\wtools2>python manage.py runserver Traceback (most recent call last): File "F:\ATSG\FrontEnd\wtoolgui\venv\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv self.execute(*args, **cmd_options) File "F:\ATSG\FrontEnd\wtoolgui\venv\lib\site-packages\django\core\management\commands\runserver.py", line 61, in execute super().execute(*args, **options) File "F:\ATSG\FrontEnd\wtoolgui\venv\lib\site-packages\django\core\management\base.py", line 398, in execute output = self.handle(*args, **options) File "F:\ATSG\FrontEnd\wtoolgui\venv\lib\site-packages\django\core\management\commands\runserver.py", line 68, in handle if not settings.DEBUG and not settings.ALLOWED_HOSTS: File "F:\ATSG\FrontEnd\wtoolgui\venv\lib\site-packages\django\conf\__init__.py", line 82, in __getattr__ self._setup(name) File "F:\ATSG\FrontEnd\wtoolgui\venv\lib\site-packages\django\conf\__init__.py", line 69, in _setup self._wrapped = Settings(settings_module) File "F:\ATSG\FrontEnd\wtoolgui\venv\lib\site-packages\django\conf\__init__.py", line 170, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "C:\Users\Muhammad Usman\.pyenv\pyenv-win\versions\3.10.0\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked ModuleNotFoundError: No module named 'wtools2' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "F:\ATSG\FrontEnd\wtoolgui\wtools2\manage.py", line 47, in <module> execute_from_command_line(sys.argv) File "F:\ATSG\FrontEnd\wtoolgui\venv\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line utility.execute() File "F:\ATSG\FrontEnd\wtoolgui\venv\lib\site-packages\django\core\management\__init__.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "F:\ATSG\FrontEnd\wtoolgui\venv\lib\site-packages\django\core\management\base.py", line 367, in run_from_argv connections.close_all() File … -
how to solved django OperationalError - attempt to write a readonly database?
I have Django web in linux(digitalocean), and use sqlite3. I have three users sqlite3. When I use: python3 manage.py runserver 0.0.0.0:8000 --> everything is good. But When I use: sudo systemctl restart apache2 --> when I open user login page and when logging, I receive error: attempt to write a readonly database. I tried: sudo chmod a+w db.sqlite3 chown apache:apache db.sqlite3 Folder structure: -myproject --projectenv --myapp ----myapp ----firstapp ----manage.py ----db.sqlite3 -
Is there a way to dynamically select schema to execute SQL queries in Django?
I have a Django app which have a model that stores SQL queries that should be executed on another one of the multiple databases. There is also a column called schema in that model which is used to store the schema where the query is to be executed. class Query(BaseModel): STATUS_CHOICES = [ ('active', 'Active'), ('inactive', 'Inactive'), ] name = models.CharField(max_length=100) syntax = models.TextField() description = models.TextField() group = models.ForeignKey(Group, on_delete=models.DO_NOTHING) schema = models.CharField(max_length=20) database = models.CharField(max_length=20) status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='active') extras = models.TextField() How do I execute this raw SQL query stored in that model in the schema name that's stored in the same record. There could be different sql queries with different schemas too. Everytime the query is executed, it should dynamically take the schema from the record and run it in the database. I know we can use the .using() in the ORM to specify the database to run the query on. Is there any such similar thing to specify schema? -
I can't import modules from my own project
I'm trying to import the ApiRequest class that I created from my project_datafit.utils but it's not working, I created a folder called "venv" inside my python folder and in it I created the virtual environment "Ambiente_datafit" I already downloaded all my libraries and I already configured vs code to use the python interpreter from "ambiente_datafit", before the other imports weren't working either, but after I fixed the interpreter they worked, now only the imports that I get from my own project like utils or My models are not going and keep saying could not be resolved, what do I do? (https://i.stack.imgur.com/ngQnc.png) It seems that Python doesn't recognize my files, what should I do? -
django makemigrations ModuleNotFoundError: No module named 'django.Falsedb'
I am learning to use Django, and when trying to install Crispy Forms and running 'makemigrations,' I encounter the following error: Traceback (most recent call last): File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/db/models/options.py", line 275, in _get_default_pk_class pk_class = import_string(pk_class_path) File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/utils/module_loading.py", line 30, in import_string return cached_import(module_path, class_name) File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/utils/module_loading.py", line 15, in cached_import module = import_module(module_path) File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked ModuleNotFoundError: No module named 'django.Falsedb' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/javier/Desktop/pd110/src/manage.py", line 22, in <module> main() File "/home/javier/Desktop/pd110/src/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line utility.execute() File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/__init__.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/base.py", line 412, in run_from_argv self.execute(*args, **cmd_options) File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/base.py", line 458, in execute output = self.handle(*args, **options) File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/base.py", line 106, in wrapper res = handle_func(*args, **kwargs) File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/commands/makemigrations.py", line 156, in handle loader.check_consistent_history(connection) File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/db/migrations/loader.py", line 313, … -
Django filter name__icontains not working
I have some model with name field as: name = models.CharField(max_length=255, verbose_name='Name', db_index=True) I want to filter my records by some string WITHOUT REGISTERING, for example a record with name "Apple" should be found by the strings "Apple", "apple", "aPPle", "ApPpLe" and so on. I use: results = Page.objects.filter(name__icontains=query) But it doesn't work. Various combinations like: results = Page.objects.filter(Q(name__iexact=query) | Q(name__icontains=query)) or results = Page.objects.filter(name__iexact=query) Not working.The search is always case-sensitive. How to fix this? I am using Django 4.2.6 and Postgresql 14.9 on Mac m1 on Mac OS Ventura 13.4.1. I want to filter my records by some string WITHOUT REGISTERING, for example a record with name "Apple" should be found by the strings "Apple", "apple", "aPPle", "ApPpLe" and so on. -
how to make auth with react and django in spa app
im using this article https://testdriven.io/blog/django-spa-auth/ but woww all of this is confusing tbh. im using react and react router but i tried both second way and still it didnt work my question isnt really about how to fix this since i feel like its wrong because your reinventing the wheel and you should use 3rd party app can someone tell me what im supposed to do btw if you still think this is a good solution from the article ill show you my github rep so if you wanna se whats wrong https://github.com/MicheleAwada/blog (this is because they asked me and stuff) i tried finding a third party app. but i didnt find it. i thought the spa auth would work but i got a csrf cookie not set error -
MultiValueDictKeyError at /buyer/register/ end in post and put requests Django rest framework on pythonanywhere
I am a beginner to django, I created eCommerceAPI as a project. The project features CRUD API designed to perform operations like user registration, user login, product management etc. for an ECommerce shopping website. The application is working fine on my local but I am having issues during post and put request on after deploying it on pythonanywhere.com. @api_view(['POST']) def register(request): name = request.data['name'] email = request.data['email'] password = request.data['password'] address = request.data['address'] try: cursor = connection.cursor() cursor.execute('''INSERT into buyer (name, email, password, address) values("''' + name + '", "' + email + '", "' + password + '", "' + address + '")') return Response({"Message": "Registration sucessfull."}) except db.OperationalError as e: return Response(list({'Error': e}), status = 400) except db.Error as e: return Response(list({'Error': e}), status = 400) except: return Response({'Error': 'Invalid Parameter'}, status = 400) Complete Traceback enter image description here The application is working fine on my local again, can anyone point out the problem here with pythonanywhere.com ?? I tried changing name = request.data['name'] to: name = request.POST['name'] name = request.POST.get('name') after surfing about the issue here and there but none of them worked for me. You can access the live project here: Click here Github link … -
Hello Everyone I am Trying to create Cash Payments Getaway in Django
hello everyone i am trying to create a function in django to create cash payment and i can't did this and user fille order form and choice case payment and order will send successful please help me!!!! Models.py from django.db import models from accounts.models import Account from store.models import Product, Variation # Create your views here. class Payment(models.Model): PAYMENT_METHOD_CHOICES = ( ('cash', 'Cash'), ('online', 'Online'), ) user = models.ForeignKey(Account, on_delete=models.CASCADE) payment_id = models.CharField(max_length=100) payment_method = models.CharField(max_length=20, choices=PAYMENT_METHOD_CHOICES) amount_paid = models.CharField(max_length=100) status = models.CharField(max_length=100) created_at = models.DateTimeField(auto_now_add=True) def __str__(self): return self.payment_id def __str__(self): return f'{self.payment_method} - {self.amount}' class Order(models.Model): STATUS = { ('New', 'New'), ('Accepted', 'Accepted'), ('Completed', 'Completed'), ('Cencelled', 'Cencelled'), } user = models.ForeignKey(Account, on_delete=models.SET_NULL, null=True ) payment = models.ForeignKey(Payment, on_delete=models.SET_NULL, blank=True, null=True) order_number = models.CharField(max_length=50) first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) email = models.EmailField(max_length=50) phone_number = models.CharField(max_length=50) address_line_1 = models.CharField(max_length=50) address_line_2 = models.CharField(max_length=50, blank=True) city = models.CharField(max_length=50) pin_code = models.CharField(max_length=50) state = models.CharField(max_length=50) country = models.CharField(max_length=50) # shope_image = models.ImageField(upload_to='photos/Shope_images') order_note = models.CharField(max_length=50) order_total = models.FloatField() # gst = models.FloatField() status = models.CharField(max_length=50, choices=STATUS, default='New') ip = models.CharField(blank=True, max_length=50) is_ordered = models.BooleanField(default=False) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) def full_name(self): return f'{self.first_name} {self.last_name}' def full_address(self): return f'{self.address_line_1} {self.address_line_2}' def add_multiple_orders(user, … -
Django with Cyberpanel deployment - Internal Server Error(500)
I'm trying to deploy the Django App in vps with the Ubuntu and Cyberpanel. But i can see the demo project with the domain URL. But with my project i'm ony getting the Internal Server error. ├── db.sqlite3 └── myproject ├── __init__.py ├── __init__.pyc ├── manage.py ├── media │ ├── assets │ ├── css │ ├── fonts │ ├── images │ ├── js │ └── video ├── requirements.txt ├── myproject_app │ ├── admin.py │ ├── apps.py │ ├── app_util_mail.py │ ├── app_util_mail.pyc │ ├── __init__.py │ ├── __init__.pyc │ ├── migrations │ ├── models.py │ ├── templates │ ├── tests.py │ ├── views.py │ └── views.pyc ├── settings.py ├── settings.pyc ├── urls.py ├── urls.pyc ├── wsgi.py └── wsgi.pyc and this is the lite speed context file context / { type appserver location /home/test.com/public_html/my-demo binPath /usr/local/lsws/fcgi-bin/lswsgi appType wsgi startupFile myproject/wsgi.py envType 1 env LS_PYTHONBIN=/home/test.com/public_html/bin/python2.7 env PYTHONHOME=/home/test.com/public_html/ } All i'm getting is that the internal server error. But i will only run my project with the python2 manage.py runserver & gunicorn wsgi without the app name. When i tried to run the project with the app name. It shows the error as unknown command. -
Apply Django REST JWT on admin panel
In Dajngo service, i use Simple JWT. It works great with frontend server except for one problem... When I am logged into the admin panel, the frontend authentication with JWT is not working properly. As far as I understand, this is due to the fact that the admin panel works using sessions (which it stores in cookies) rather than JWT tokens. Is there any way to connect JWT authorization to the admin panel? -
Django 3.2 REST API : Postgressql video upload fails
I'm attempting to upload a video of 32 MB in 2k resolution to my backend django 3.2 rest api with postgres-sql as my database engine deployed on GCP ubuntu with v2 cpus and 8 Gb memory. My front end flutter app crashes with a buffer pool eviction error. I focussed on the frontend for the past few hours. However upon inspecting the docker-compose logs just to rule out any backend issue, I get the following just before it fails on the front end : video-project-postgresql-db | 2023-11-01 12:44:56.708 UTC [27] LOG: checkpoint complete: wrote 79 buffers (0.5%); 0 WAL file(s) added, 0 removed, 0 recycled; write=7.636 s, sync=0.007 s, total=7.654 s; sync files=48, longest=0.002 s, average=0.001 s; distance=301 kB, estimate=301 kB; lsn=0/21C93A0, redo lsn=0/21C9368 Need to understand what this means. Help appreciated. -
In a mysql-django-axios-react setup.... how to update a column in the db using its own value
Long time listener, first time caller.... learned so much from the forum and its community and many thanks to the platform and the community. Hopefully can get my skills up to contribute. Have a Mysql - Django - Axios - React setup. I can use Axios PATCH easy enough in react to issue an update through Django RFW to update a column in the db. But I'm stuck on how to update the column using the existing value in the column. For example in db language: table.column1=table.column1+x I tried a few things like passing a string as the data object but get a 400/bad request/"column requires an integer value" error from django RFW. Rookie mistake with db background... Last thing I tried was using the django F() expression to construct the data object to pass through axios.patch, and although no errors and get status 200 back from django, nothing happens, no update to the column. const col = (column1=F('column1')+${x}) axios.patch(localhost:8000/Model/${id},col) When I look at the browser console/network traffic I see FormData that is getting passed from axios to django as: (column1: F('column1') 9) /* 9=x */ Which is why I'm guessing nothing happens without the "+" Obviously I could axios.fetch, … -
is there any way to make possible the post request in my django and react project?
the frontend code is `import React, { useState, useEffect } from 'react'; import axios from 'axios'; import { ToastContainer, toast } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; import Select from "react-select"; function AddDetails() { const [formData, setFormData] = useState({ first_name: '', last_name: '', mobile_number: '', services: [], years_of_experience: '', license_certificate: null, min_charge: '', charge_after_one_hour: '', street_name: '', house_number: '', ward: '', panchayath_municipality_corporation: '', taluk: '', district: '', state: '', country: '', }); const [services, setServices] = useState([]); const [selectedServices, setSelectedServices] = useState([]); useEffect(() => { // Fetch the list of services from the Django backend axios .get('http://127.0.0.1:8000/services/') .then((response) => { setServices(response.data.results); }) .catch((error) => { console.error(error); }); }, []); const handleChange = (e) => { const { name, value } = e.target; if (name === 'services') { const selectedServices = Array.from(e.target.selectedOptions, (option) => option.value ); console.log('Selected Services:', selectedServices); setFormData({ ...formData, services: selectedServices, }); } else { setFormData({ ...formData, [name]: value, }); } }; const serviceOptions = services.map((service) => ({ value: service.id, label: service.Title, })); const handleSelectChange = (selectedOptions) => { setSelectedServices(selectedOptions); const selectedServiceIds = selectedOptions.map((option) => option.value); setFormData({ ...formData, services: selectedServiceIds, }); }; const handleFileChange = (e) => { const file = e.target.files[0]; if (file) { const reader = new FileReader(); reader.onload … -
How to get FCM_SERVER_KEY in Django 2023.11
I got firebase json file then want to get FCM_SERVER_KEY FCM_DJANGO_SETTINGS = { "FCM_SERVER_KEY": "wbhsfvbyewfuibwerugbjdsnugvbrfdfhbvjhbsdufhgvgtfhghuyhyuljhblkjhbliukjhiubbhfuvbkhersbfvcuhefhyuer" } I am expecting answers with pictures -
Django 4.2.6: Installing Different Admin Templates for Different Custom Admin Sites
I'm facing an issue while trying to install different admin templates for different custom admin sites in Django. Specifically, I want to use the default django.contrib.admin template for the default admin site and enable django-jet-reboot for a custom admin site. The problem I'm encountering is that when I install django-jet-reboot, it gets enabled for all admin sites, including the default one. Could someone please guide me on how to correctly install and apply different admin templates for distinct custom admin sites in Django? Thank you in advance for your assistance! I have tried to write a custom djanto template loader that reads a field from the settings: The following is a configuration that assiciate a given admin site with a corresponding template #settings.py ............. ADMIN_TEMPLATE_ASSOCIATION = { 'admin': { "template": "django.*", "exclude_templates": [ 'jet.*', 'jet.forms', 'jet.dashboard', ] }, 'first_admin': { "template": "jet.*", "exclude_templates": [ ] }, } .............. """ Wrapper for loading templates from "templates" directories in INSTALLED_APPS packages. """ #myapp.loader.py from pathlib import Path import re from django.template.utils import get_app_template_dirs from .filesystem import Loader as FilesystemLoader """ Wrapper for loading templates from "templates" directories in INSTALLED_APPS packages. """ from django.template.utils import get_app_template_dirs from .filesystem import Loader as FilesystemLoader from …