Questions tagged [django]

Django is an open-source server-side web application framework written in Python. It is designed to reduce the effort required to create complex data-driven websites and web applications, with a special focus on less code, no-redundancy and being more explicit than implicit.

django
Filter by
Sorted by
Tagged with
0 votes
1 answer
1k views

How can I add parameters to a Python Shell command?

I have a Django + Python application. I have a python script that takes requirements as command line options. The issue for me is that when I try to put in the command line arguments the script fails ...
ironmantis7x's user avatar
0 votes
1 answer
76 views

How do I have the deletion of a user in Django trigger execution of some additional code?

In my Django application, when a user is created, a database is created too. This is defined in my registration view. I have the database creation to make up for the lack of support for dynamic models....
user avatar
0 votes
1 answer
139 views

How to add objects to a different model when using a form in Django?

I have a few forms that retrieve objects through a ForeignKey, e.g. Flight, Trip. So, for example, when someone tries to create a new Trip, they can choose an Hotel from a dropdown. My question is: ...
overclock's user avatar
  • 605
0 votes
1 answer
117 views

Combine independent form with DetailView

I want to display DetailView and independent form to send API request to the other website server. I made views.py but only i get is empty page. I'm trying to figure out how to adjust it for over past ...
ImustAdmit's user avatar
0 votes
1 answer
1k views

python-rq scheduler count the number of times job executed

I'm using Django-rq which has the functionality of Scheduling the jobs with specified interval. https://github.com/rq/django-rq#support-for-rq-scheduler task = scheduler.schedule( scheduled_time=...
Arbazz Hussain's user avatar
0 votes
1 answer
86 views

Can “list_display” in a Django ModelAdmin display other fields of realated table?

I can't get "list_display" to display field from related table. models.py class product(models.Model): product_id = models.AutoField(primary_key=True) EAN = models.CharField(unique=True, ...
Fortelll's user avatar
1 vote
1 answer
691 views

Sending variable Client Side (JS Ajax) to Server Side (Python Django)

I am using Python 3.7.4 with Django 3.0.3 and I have a script Ajax in javascript run in the front end app. When the user click in link, a variable must to be sending to back end python. See the ...
Rafael Christófano's user avatar
3 votes
1 answer
114 views

Python - Django - Filter and count all people in first year from start date

I need to count all the people who are in the first year of the contract. I even made several attempts and failed. Can anyone help me? Thanks! Model: class Contracts(models.Model): person = ...
Filipe Fonseca's user avatar
1 vote
1 answer
128 views

Getting model instance by passing field name and not primary ID

I want to get a model instance using URL as http://127.0.0.1:8000/db/User/email (i.e. using email as a query) and not by http://127.0.0.1:8000/db/User/1/. How to approach this. Model: class ...
unknown29's user avatar
1 vote
2 answers
556 views

Django REST Serializer Many to Many field displays only through table id, need list of many records

How do i get list of Many 2 Many field objects? I am just getting the ID. This one is MainHost class which is having Many2Many field class MainHost(models.Model): host_id = models.IntegerField(...
saar's user avatar
  • 31
0 votes
1 answer
155 views

Tabindex inDjango template does not move cursor to correct field

I have a Django form and want the user to be able to tab to the username, password and login button in that order. tabindex does not seem to work in my template. Instead it moves to username, login ...
Psionman's user avatar
  • 3,367
0 votes
2 answers
1k views

Django rest API, nested serializer add/edit multiple real estate images to one listing?

I am pretty stuck working with DRF for the first time. I am looking to upload multiple Images to a single real estate Listing. My image model class Image(models.Model): photo = models....
master_j02's user avatar
2 votes
2 answers
2k views

Django Rest Framework - deserialization of a TaggableManager field

I used django-taggit to add tags to my model. Django Version: 2.2.10, Python Version: 3.8.1 Now I'm trying to integrate tags with django rest-framework, e.g. CREATE/UPDATE/REMOVE model instances with/...
pastoreerrante's user avatar
2 votes
1 answer
2k views

Celery task to process data from database Postgres and django

I'm trying to use celery and celery beat to run a scheduled task to process data from the database, but when I try to run the task I get this error "django.db.utils.OperationalError: FATAL: role "...
tee's user avatar
  • 31
1 vote
0 answers
109 views

Race condition in Django while using transaction

Using Django, I got the following (minimal) model : from django.db import models from django.contrib.postgres.fields import JSONField class MyModel(models.Model) files = JSONField(default=list) ...
Blusky's user avatar
  • 3,616
3 votes
2 answers
2k views

Django, Template not found

I'm trying to render this HTML File (An Home page) And I get an error that template is not found. #views.py from django.shortcuts import render def index(request): """Homepage""" return ...
user avatar
0 votes
1 answer
199 views

'str' object has no attribute 'get', AttributeError at /add-to-cart/shirt

I am getting above stated error after lining some modification in models and views and here are the associated code: def add_to_cart(request, slug): item = get_object_or_404(Item, slug=slug) ...
Mir Stephen's user avatar
  • 1,828
0 votes
1 answer
125 views

Python Django - Variables shared between multiple users

I am working on a project written in python and using django to build a website as well. I have a function which is pulling the information from a website and putting that information into a ...
Pablo Quesada's user avatar
0 votes
2 answers
150 views

Update whole table to apply new custom save() method

I just made change to a model with a score attribute to have a new save() def save(self, force_insert=False, force_update=False, using=None, update_fields=None): if self.id: if self....
Progger's user avatar
  • 35
0 votes
1 answer
858 views

Django Rest Framework very slow when accessing user properties

Everytime I make a drf request to access user properties, such as: def StatusView(request): current_user = request.user if current_user.is_anonymous: return HttpResponse("none", ...
Mario Deaconescu's user avatar
0 votes
1 answer
793 views

{% if any([None]) %}show{% endif %} in template creates TemplateSyntaxError

I'm getting a strange error. Putting {% if any([None, 1]) %}show{% endif %} in my Django template creates a TemplateSyntaxError. Experimentation shows that {% if True %}show{% endif %} works so I ...
DrewSSP's user avatar
  • 359
1 vote
1 answer
310 views

Sequentially execute Multiple R/W queries in same django views function

I have read and write queries in my single Django view function. As in below code: def multi_query_function(request): model_data = MyModel.objects.all() #first read command ...(do something)....
khaldi's user avatar
  • 472
1 vote
2 answers
347 views

I can't link CSS file in the html file on with django

I can't link the CSS file in the HTML file, I tried in another example html css alone without django it's work but in django I have problems. ''' <html lang="en"> <head> <...
user avatar
1 vote
1 answer
34 views

Accessing manually rendered form fields from Jquery

When I render a form normally my code will validate the image file and send it through. If I manually render the form fields the validation falls. Normal Form: {{ form }} Manually rendered fields: ...
David Alford's user avatar
  • 2,224
-1 votes
2 answers
102 views

How do I get image from Profile Model

How can I get the image from Profile Model link with foreignkey User. I tried {% for user in users %}{{ user.profile_pic }}{% endfor %} with img src this do not display the image. class Profile(...
GistDom Blog's user avatar
4 votes
1 answer
2k views

django-q qcluster starts and exits while running in Pycharm Debug

I'm running a Django project with django-q in PyCharm. manage.py runserver is running in one instance, and manage.py qcluster is running in another. qcluster starts up fine, then immediately exits ...
JosiahDub's user avatar
  • 147
0 votes
2 answers
873 views

The empty path didn't match any of these (django)

A similar question was asked here in The empty path didn't match any of these. The solution did indeed work when I included the path('',include('projects.urls')) within personal_portfolio.py. But ...
Jossie Calderon's user avatar
0 votes
0 answers
255 views

Implementing a 3x3 image grid using Django

I am trying to implement a 3x3 grid in Django. Further notes: Within each grid square I should be able to place images sourced directly from my computer. The images should fit each grid square ...
Dom's user avatar
  • 43
2 votes
1 answer
1k views

Django rest api root view showing links of another app

I have created a projects which has two apps in it, app1, app2 both having, router = routers.DefaultRouter() in its url.py, both of them as a standalone app ie if other app router is commented, will ...
Ajay Tom George's user avatar
4 votes
2 answers
24k views

How to scrape google maps for all data using python

I am trying to scrape the title, phone number, website, address, rating, number of reviews of a place from google maps using python. For example, the restaurant Pike's Landing (see google maps URL ...
Kazi Kowshik's user avatar
0 votes
1 answer
128 views

Unable to save relationship between two objects with Django Rest Framework

I am building a Django/React App to allow users to submit orders that need to go from A to B. The user initially saves the addresses in the database and then he/she selects it in the order form. When ...
matcarf4802's user avatar
0 votes
1 answer
1k views

Jinja2 does not show in the webpage correctly

Using Django I have to create a basic website to display the elements inside the SQL database on the webpage. Right now, I have created a basic HTML template to start from there but since I have ...
LtMuffin's user avatar
  • 219
0 votes
0 answers
41 views

How to properly configure static folder for django's admin files

I have deployed project on production (django+gunicorn+nginx) My project structure is as follows forecast # this dir of os.path.join(Base_Dir) manage.py forecast settings.py ...
Наглый Спамер's user avatar
1 vote
1 answer
433 views

Django Testing - SimpleCookie and Session

Problem: My testing client appears to log out once i attempt to set a cookie. I have workspace (project) object that i want my client to access. The access itself works fine, but as soon as i attempt ...
michal111's user avatar
  • 410
3 votes
1 answer
1k views

How to zip multiple uploaded file in Django before saving it to database?

I am trying to compress a folder before saving it to database/file storage system using Django. For this task I am using ZipFile library. Here is the code of view.py: class BasicUploadView(View): ...
reasm001's user avatar
  • 177
0 votes
1 answer
161 views

Django: Adding social authentication to site

I'm a beginner in Django and I'm studying Django from the book "Django 2 by Example", written by Antonio Mele. I'm trying to add social authentication to my site(book page no. 251) {project name-...
Sheraram_Prajapat's user avatar
0 votes
0 answers
60 views

How to print specific number of tables per page?

While I was working on a project I needed to generate around 2000 small tables which I also have to print in pages. I was generating those tables via using a for loop within my django project using ...
Rakibul Islam Prince's user avatar
3 votes
1 answer
936 views

[FreeTDS][SQL Server]Login failed for user

I am developing on a windows and trying to run the Django application in Linux container with Gunicorn and Nginx to deploy it to Linux machine in production. I mostly used this Connect docker python ...
Jennosian's user avatar
  • 195
0 votes
1 answer
270 views

How to get a pre-populated form while updating form in django

This is my forms. class CreateBooksForm(forms.ModelForm): languages = forms.CharField(widget=forms.TextInput) file = forms.FileField(widget=forms.FileInput(attrs={'accept':'application/pdf'})...
manish's user avatar
  • 302
0 votes
2 answers
669 views

Serial number in Django admin list view

I have the following list view in Django admin. How do I show serial number for every entry? Meaning numbering the list given in the list below. Also, this serial number should also take into account ...
Mithil Bhoras's user avatar
2 votes
1 answer
1k views

Deploying django, channels and websockets with nginx and daphne

I am trying to deploy a django app that uses channels and websockets, with nginx and daphne. When I was using uwsgi, here was my nginx file: upstream django { server unix:/run/uwsgi/...
Larry Martell's user avatar
0 votes
1 answer
1k views

Tree View structure in web form using Django

I want to create a webform in Tree view using Django. I am completely new to it and could not able to understand how to make it. I tried the following code in html <!DOCTYPE html> <html> ...
RSK Rao's user avatar
  • 313
0 votes
1 answer
503 views

Django - Handle all exceptions with custom templates

I want to be able to throw exceptions with any status code. I have this template structure templates |---error | |----401.html | |----403.html | |----404.html | |----451.html | |----500....
Myzel394's user avatar
  • 1,256
0 votes
2 answers
1k views

Django - redirecting back to a page shows http response (Json data) and not rendering

Question: What would be the best way of dealing with this so that the json response isn't shown if the user redirects like this? Or to take the user back to the state of the quiz before the data is ...
Darren Lally's user avatar
0 votes
1 answer
132 views

Django specify manually fields to include as nested JSON

With django-rest-framework I'm creating a REST API where I can access and modify information about people in a city. People belong to a city, and therefore have a foreign key linking to the City model....
Simen Russnes's user avatar
0 votes
0 answers
29 views

Deploying to GoogleAPP ENGINE

on deploying my application to google app engine i encountered the following error when i try to click on the endpoints i have, is there away to solve this since i cant seem to do migrations on google ...
Robin k.'s user avatar
1 vote
2 answers
549 views

Store data from multiple URLs in python

I have 10 URL's which are csv file. I want to store data from multiple URL's in a list in python. All URL's are a csv file in same format. I have tried: url = request.GET.get('url') #for ...
code_nation's user avatar
1 vote
0 answers
129 views

How can I toggle a form having prefilled content with an edit button in django

I have a form that users can fill to leave a review. On the same page, the reviews are displayed with a button to edit the review. When the edit button is clicked, I would like for the form to be pre-...
Jimi Windmills's user avatar
0 votes
0 answers
23 views

Django retrieving submitted value from table

I am trying to create a simple django project, with the following model: class dealerinfo(models.Model): name = models.CharField(max_length=255) required_field_1 = models.ImageField(...
Aurphillus's user avatar
16 votes
1 answer
4k views

Can't debug Django unit tests within Visual Studio Code

I want to be able to run and debug unit tests for a Django project from within Visual Studio Code. I am an experienced developer, but fairly new to both Django and Visual Studio Code. The crux of ...
Jerry K.'s user avatar
  • 509