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.
214,393
questions
0
votes
0answers
6 views
Can I post the javascript array to the database in django framework?
I am new to django, I am having an users table and designs table as given below
class designs(models.Model):
id=models.IntegerField(primary_key=True)
image = models.ImageField(...
1
vote
1answer
16 views
How to populate initial values of form from queryset
I have a FormView with a get_initial method which I am trying to use to populate the form. I am trying to get the EmployeeTypes of the receiver of the memo as values in the form.
def get_initial(...
0
votes
0answers
11 views
Error while updating mongodatabase collections from django app using djongo
I am facing an error. I am trying out the polls tutorial as provided in the django documentation. The problem is with the django 'F' function. I am trying to update the number of votes for a choice. ...
0
votes
0answers
13 views
Django Model seeking alternative to many to many fields
I am writing an exam system, below is my model:
class Exam(models.Model):
name = models.CharField(
max_length=100
)
class Topic(models.Model):
name = models.CharField(
...
0
votes
1answer
25 views
Why is my Django form is not displaying anything?
I am following a tutorial in which we will create a form to hold simple object parameters.
Here's the code:
forms.py
from django.forms import ModelForm
from .models import Item
class ItemForm(...
0
votes
1answer
29 views
Join and format array of objects in Python
I want to join and format values and array of objects to a string in python. Is there any way for me to do that?
url = "https://google.com",
search = "thai food",
search_res = [
{
...
0
votes
0answers
10 views
Webhost Platform for PostGIS, Django and Celery
I'm currently developing a django web app. I'm trying to decide which platform is best suited to host it. I was considering PythonAnywhere but it seems like they don't support celery or other long ...
1
vote
1answer
23 views
How to initialize form with some parameters of model instance
I would like be able to send SMS/Email notifications manually using the groups/users of a model instance. Let's say the model looks like this:
class Memo(models.Model):
title = models.CharField(...
0
votes
0answers
10 views
Crispy Django Form With RadioBox - Using InlineRadios
I want to style in Radio button in Django using Crispy Form. However, I have successful making use of CSS which is applied to the form but I need to display the form n inline format. After rendering ...
0
votes
1answer
15 views
Django TestCase object has no attribute 'login'
I have used selenium to test my login method and it works fine. Then, I tried to test other parts of the website. So, I needed to create a user in my test. To do that, I've used client instead of ...
0
votes
0answers
8 views
Send mail inside action django-rest-framework
i'm learning django restframework by myself I'm trying to send a mail with sengrid inside an action
enter image description here
The mail doesn't send Sorry for menglish thank you
0
votes
0answers
15 views
Django background task repeating more than it should
I am trying to run a django background task every 30 seconds, as a test I'm having it print "hello", but instead of printing every 30 seconds it is printing about every second or less very quickly. ...
-1
votes
0answers
12 views
How to make the user visible to al his group activities
I am doing a django-rest-framework project in which one can create groups by adding member’s email id and the logged in user should be able to see all the group activities.
I used django-multi-email-...
0
votes
1answer
23 views
Failed lookup for key in templates
I am trying to get Specific List in Dictionary, but first I got the error: "fail to lookup for key", searching on internet I found out a tread with this solution:
{% with obj1.page.val2 as val2 %}
...
0
votes
1answer
26 views
Django model method error: missing 1 required positional argument: 'self'
I want to do some calculations inside a model and between attributes. I want 3 fields that can be entered by the user to add the model, but those fields get concatenated into a non-editable field that ...
0
votes
0answers
10 views
Session data corrupted in Django session
I have an application which using Django 2.0 and I'm facing with an issue about session data today. (SECRET_KEY is a static string, and consistent among the app so this might not is the issue)
The ...
0
votes
0answers
13 views
How to return user session id alongside Django rest serializer output
I'm writing a web application with Django. In one of my APIs which is using Django rest_framework, I want to return user's session ID alongside the default response. I know how to get the session ID ...
0
votes
1answer
29 views
python - group values when generating a json
I am generating below JSON using a piece of code.
Basically, I need to group my generated JSON group by continent, and then country and languages
[
{
"continent": "South America",
...
0
votes
0answers
12 views
How can I convert a duration or a string to an integer in a queryset in Django views.py?
I need to calculate the time difference between two rows. This duration then needs to be adjusted up to 1 if the total is 0, or if the total is over 15 minutes, adjusted to 0--I was going to put this ...
1
vote
2answers
27 views
Django queryset caching with exists() and values_list()
Let's say, I'm trying to change the name of all profiles whose name is John to Mike
queryset = Profile.objects.filter(name='John')
Method 1:
if queryset:
queryset.update(name='Mike')
logger....
0
votes
1answer
17 views
Using Django to display images
I am attempting to use Django to display 3 random images from a large list of user submitted images. Each image has other values associated with it like the author, so I've been making each image a ...
0
votes
2answers
34 views
Why does django send_mail fails to send email with no errors?
I want to use send_mail in django, however it doesn't send any email. Here is my settings:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER =...
0
votes
0answers
9 views
Why can't I PATCH Django REST Framework PrimaryKeyRelatedField to empty list?
I'm running into a weird issue in Django REST Framework. I'm attempting to add & remove groups to/from users using PATCH requests.
I am able to PATCH to /api/users/:id/ to update the groups list, ...
0
votes
0answers
29 views
My form does not send data to the db django
My form does not send data to the database.
I have a form that after entering data and clicking 'Order' should send information to the database. However, this does not happen.
It is a 'cart' which, ...
0
votes
0answers
13 views
wagtail menus return an empty list menu_items
after added wagtailmenus to my wagtail project and it worked well, but when i add an item to my main menu and try to use it in my navbar it always return in empty list... it doesn't matter how many ...
1
vote
1answer
23 views
Annotating data in Django Templates
I am attempting at rendering annotated data into my template
My models looks like this
class Content(models.Model):
title = models.CharField(max_length=255)
body = models.TextField()
reviews_total =...
0
votes
1answer
20 views
COPY failed: stat /var/lib/docker/tmp/docker-builder<num>/server/requirements.txt: no such file or directory
Appears to be some kind of context issue. I'm trying to figure out why this would work fine when spinning up a local Kubernetes cluser with Skaffold, but is failing to build the image properly when ...
0
votes
0answers
19 views
Issue with question mark in Django url [duplicate]
Here is the example link: abc.com/Hi-Python?
So, in the backend of Django, I need data "Hi-Python?", but I'm getting - "Hi-Python"
url(r'^@(?P<title>[a-zA-Z0-9_\.!,\-\?\:\w\+]+)$', views.title,...
0
votes
0answers
18 views
ImportError: cannot import name 'python_2_unicode_compatible' when running migrations for Django-Invitations
First, I might want to mention I'm a beginner with Django. I'm trying to install Django-Invitations on my app to send sign up invitations. I followed their README instructions.
pip install django-...
0
votes
0answers
28 views
TemplateSyntaxError: Could not parse the remainder: '()' from 'size.toLowerCase()' [duplicate]
I am working through Python+Django on PythonAnywhere. I am generating a .html file by using a ListView I wrote. I want a table that contains data which will change based on drop down selections.
I am ...
0
votes
1answer
14 views
How to grant atomicity on clean() method in django Models
I'm currently using django's clean() method to implement custom validations in a Model.
A have a DB for example that is 1:m and have the following structure:
| Id | Foreign Key | Date ...
0
votes
0answers
25 views
Django Cron, execute def from views
I have a problem.
I needto implement a function that will be called cyclically
I have to call dashgenerate functions because it generates data records
this cron.py:
from django_cron import ...
0
votes
0answers
18 views
ModuleNotFoundError: No module named <module_name> although module was installed
I'm trying to run server for my django app, and I've used TinyMCE editor for admin panel. Although I've installed it with command pip3 install django-tinymce application returns me such error:
...
0
votes
1answer
25 views
How do I change the default Django engine database from db.sqlite3 to a mysql database populated with test data?
This is my first time doing this so please bear with me.
What I am trying to do:
Change the 'DATABASES' setting in my 'settings.py' from the 'ENGINE: 'django.db.backends.sqlite3' to a pre-populated ...
0
votes
1answer
39 views
How to route to a url based on data entered in Django form?
At first , I would like to take an integer input from user . After getting the input , I would like to go to the url based on what the user has entered . However , I am not able to implement it .
...
0
votes
1answer
22 views
Django Webhook creates double database entries
I'm currently using Django to code a webhook application for google Dialogflow.
It was working fine, I was basically done.
For some reason, I now started encountering various randomly appearing ...
0
votes
1answer
16 views
Django Custom Permissions not synced to DB
I am newbie to Python and Django. I am trying to addd custom permissions using Django documentation. I added new permissions to model meta data.
class Project(models.Model):
class Meta:
...
-1
votes
0answers
18 views
Django rest_ramework error “Object of type UserToken is not JSON serializable”
I use django_rest framework and do authorization manually. I use tokens, which I also generate myself.
When trying to authorize an error occurs "Object of type UserToken is not JSON serializable". I ...
1
vote
0answers
18 views
Add custom log records in Django
I've added the following logging configuration to my Django App's settings.py file:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
...
0
votes
0answers
22 views
Django - save changes made to model objects and render when published
I am new to Django and working on my first project in Django. I am providing a simpler example for my application where -
I have 3 different types of users for the application.
Teacher's Assistant - ...
0
votes
1answer
13 views
How to use Google Drive to save media files for a Django app that is deployed in Heroku?
Is it possible to use Google Drive to save all the media files (image files which users will upload) from a Django app? This app will be deployed in Heroku (free). I am also aware of Amazon S3 but I ...
0
votes
1answer
14 views
How to transfer GeoQuerySet.distance(geom, **kwargs) from Django 1.8 to Django 3.0?
I found this example in the Django 1.8 documentation. And it’s very important for me to follow the same steps, but in Django 3.0 (or 2.2).
class AustraliaCity(NamedModel):
point = models....
0
votes
1answer
22 views
Is there a way to filter for more than one value in the same column of a table?
I am realy frustrated and don't know what to do.
I build a Website, where you can filter for beverages with many parameters, for example for the name of an Item, for the brand usw... But I also want ...
0
votes
0answers
14 views
unique_for_date parameter for SlugField
First, I am reading a book on django and from it have created the following models.py (entire models.py included at the end, the two fields related to the question are here):
slug = models....
0
votes
0answers
9 views
django filling a text field based on a button it is redirected from
I am trying to create a project management app
each user has multiple projects which he creates
my projects app is as follows
class projectsmodel(models.Model):
added_by = models.ForeignKey(...
0
votes
2answers
31 views
Django: return list/tuple of element.id and min(element.price) from chunks of queryset
I've a cart_detail view that will be used to offer 3x2 discounts.
So I'm making chunks of 3 elements from every element in my queryset.
Using:
def chunks(lst, n):
"""Yield successive n-sized ...
0
votes
0answers
19 views
How to check if a child in firebase database exists using Django?
the following code throws attribute error
''Database' object has no attribute 'exists''.
from django.shortcuts import render
from django.views import View
from django.views.decorators....
0
votes
1answer
32 views
Django says SECRET_KEY must not be empty
I imported a Django project from a repo, and when I try to make the migrations with
python manage.py makemigrations, I get the following exception:
File "C:\Users\Iván\AppData\Local\Programs\Python\...
0
votes
0answers
11 views
Run a test on a Python/Django cronjob
I am trying to create some tests for my Django cronjobs.
I have a file called cronjob.py:
from apscheduler.schedulers.blocking import BlockingScheduler
sched = BlockingScheduler()
from mailer....
-1
votes
0answers
14 views
Django loading javascript static files [closed]
i am trying to load a javascript static file into my Django template but only the css file loads and not the javascript file. Ive ran through the Django documentation and i cant find any information ...