Questions tagged [django]

81032 questions
1

votes
0

answer
24

Views

Print Dates range if they are available in db

from below code i am going to print date ranges that's fine but what the problem is i need to print the date ranges , those available in database only [this image shows the created_at date field which is in look model . I need these dated to be printed if user select the date rage between dec 1 to...
Access_Doomer
1

votes
1

answer
330

Views

Passing Parameters to upload_to Parameter in Django File Upload

I am using the following post to upload files in Django: https://simpleisbetterthancomplex.com/tutorial/2016/08/01/how-to-upload-files-with-django.html. In the post, it mentions that the upload_to parameter can be a callable that returns a string. In the example provided, the callable accepts two pa...
Foobar
1

votes
1

answer
68

Views

Super easy tutorial throwing django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet

I created a simple django web app. When I run the models.py file I get the following error. I've tried a number of solutions including taking out my apps one by one, reinstalling django (I have version 2.0) doing an 'ol system restart, inserting import django + django.setup(), refreshing the virtual...
Pri
1

votes
0

answer
151

Views

Django ManagementForm data is missing or has been tampered error on request.POST

When i pass request.POST parameter to my CargoUnitFormSet. It get this error in command line. File 'C:\Python27\lib\site-packages\django\utils\functional.py', line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File 'C:\Python27\lib\site-packages\django\forms\formsets.py', l...
Harun ERGUL
1

votes
1

answer
71

Views

Django: how to mock a user with FB privilegies

I need to check that the content of a template is loaded properly. However, I need a user that has Facebook integration. This is my view: def profile(request, user_id): '''A user's public pledge settings.''' user = get_object_or_404(SocialUser, pk=user_id) # We only want to show profile pages for us...
lmiguelvargasf
1

votes
1

answer
227

Views

Returning an image from a Django view using django-sslserver

I'm trying to return an image from a Django 1.11 view while using django-sslserver and Pillow. Here's a minimal view I made for testing. def get_image(request): img = Image.open('oh_noes_cat.png', mode='r') response = HttpResponse(content_type='image/png') img.save(response, 'png') return response I...
clairempr
1

votes
1

answer
29

Views

Remove data from the database when the remove button of a datatable is clicked

I am using a datatable to dispay information for the user and it is generated a delete button per row. I would like to delete the row data from the database when the user click on it. How can I do that? HTML ... $('#id_data').DataTable({ destroy: true, data:data_array_data, 'bLengthChange': false, /...
1

votes
1

answer
58

Views

How can I get the current user's group in forms.py in Django?

I have a scenario where i need to pass the logged-in user's groud name and get the list users in that group. forms.py -- in the below code i need to pass the user's group instead of Banglore class UpateTaskMaster(forms.ModelForm): def __init__(self, *args, **kwargs): super(UpateTaskMaster, self).__i...
Mohamed Naveen
1

votes
0

answer
38

Views

javascript template for showing table body

I am using ajax for updating/refreshing the cart when an item is removed from the cart table to show the updated items. ajax functionality and logic is working but could not show the following template inside {% for furniture in cart.furnitures.all %} {% include 'includes/carts/remove-furniture.htm...
pri
1

votes
2

answer
166

Views

I am having errors with Django authenticated built-in function

I have been woking in django for a while. Now i am facing some problems with built-in function in django. The error state that TypeError: 'bool' object is not callable. This kind of error happened because of statement 'print(request.user.is_authenticated())'. Here below is source code: def login_pa...
I Love Coding
1

votes
0

answer
109

Views

Wagtail can't access images on S3 - I/O operation on closed file

I'm trying to get Wagtail to store and serve images from an AWS S3 bucket. I have followed the instructions and have it working great in a test environment, however when I switch to the Production Database and Bucket, I run into problems using the Admin and occasionally the frontend too. I have: bot...
Brett
1

votes
0

answer
46

Views

Sort and set REST API data into a new list

I'm trying to create a report table based from an API, but the API currently is not sorted as I wanted it to be and I'm not sure how to rearrange it. Here's an example of how the API that look like this : [ { 'task': { 'id': 2, 'name': 'Texturing', }, 'assign_to': { 'id': 1, 'official_name': 'Roy Ha...
M.Izzat
1

votes
1

answer
38

Views

Django tags/keywords based search [closed]

I'm learning Django to build a website with a search engine. I only found documentation for full text search. However, I'm trying to implement a keywords/tags based search that I add to each item. For example, if a user searches meat, all meat products like chicken, beef, ham, will pop up. Items ca...
Bassam Mohmaud
1

votes
1

answer
98

Views

Python - How to add two model fields in models.py in Django

I have a class in my models.py class Inventory(models.Model): date = models.DateField(('Date'), default=datetime.now) product = models.ForeignKey(Product) stock_in = models.IntegerField() stock_out = models.IntegerField() balance = models.IntegerField() particulars = models.CharField(max_length=250)...
xed
1

votes
0

answer
44

Views

Showing auth. errors in Django in HTML

I'm new to Django. I have custom HTML form for login and sign up, so when I input wrong username or password my page just reloads. How can I put messages into HTML printing 'wrong password' or 'wrong username'? My URLs urlpatterns = [ path('login/', auth_views.login, {'template_name': 'login.html'}...
D. Make
1

votes
1

answer
381

Views

Django abstract user model not migrating

So I am working on implementing a custom user model, and to do so i followed tutorial 'this tutorial. These are the models: class UserManager(BaseUserManager): '''Define a model manager for User model with no username field.''' use_in_migrations = True def _create_user(self, email, password, **extr...
wtreston
1

votes
0

answer
105

Views

to_python() and from_db_value() methods overlapping in function?

I've been looking at this code example from the docs: import re from django.core.exceptions import ValidationError from django.db import models from django.utils.translation import gettext_lazy as _ def parse_hand(hand_string): '''Takes a string of cards and splits into a full hand.''' p1 = re.compi...
Sahand
1

votes
1

answer
110

Views

Popup UserCreationForm in Django

Can I popup UserCreationForm of Django? I am building a website. When I click on signup page popup signup page needs to show. Right now I have a signup page and login page and they are working but I need to popup them. I am using usercreationform of Django. Can I add Bootstrap and CSS in that form...
Dawood Basharat
1

votes
0

answer
318

Views

How can we insert dictionary(json) in mongodb with Django using djongo library?

I am building REST API Using Django, MongoDB and djongo lib My requirement is, I have to store the dynamic JSON in MongoDB through djongo model. data={'name':'xyz','age':12} year=2017 month=10 class TestModel(models.Model): year = models.IntegerField() month = models.IntegerField() customer = 'I...
Ravinarayan Singh
1

votes
1

answer
279

Views

DJango-tables2 how do I refresh/update the table on the webpage without hitting refresh button

I followed the DJango-tables2 official tutorial and was able to create data set in the terminal using: Person.objects.bulk_create([Person(name='Jieter'), Person(name='Bradley')]) However, the new data in the table on the website doesn't show up until I hit the refresh button. My question is how the...
szd116
1

votes
1

answer
41

Views

Nested Relationship Serializer Rest Framework Not Displaying Properly

I'm trying to display the attributes in the Disease Model and Evidence Model, but the attributes that is displayed on the end link are only those attributes that are present in the Rule Model. Models.py :- class Rule(models.Model): disease = models.ForeignKey(Disease, default=0,related_name='DRules'...
mutedeuphonies
1

votes
1

answer
42

Views

Highcharts Data Parsing List of lists

I'm using Django and I am trying to parse the data I am putting into my template to load into high charts. This is the first I'm using High Charts and I was unable to locate a way of parsing it this way. Right now my data is presented like [['Date', 'Product1', 'Product2'],['Dec 28 2017', 2, 2], [...
Derrick
1

votes
0

answer
158

Views

Django 1.11 static files not loading

Setting.py STATIC_URL = '/static/' PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) STATIC_ROOT = os.path.join(PROJECT_DIR,'static') TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),) There are static files in my directory, I have tried every possible solution.
Gaurav Bhagat
1

votes
2

answer
410

Views

Apache 2.2, Django, use Python 3.5

I want to run django with apache2.2 and python 3.6, after making changes in wsgy.py and virtuahost still running python 2.6 Apache/2.2.34 (Unix) DAV/2 mod_wsgi/3.2 Python/2.6.9 configured -- resuming normal operations Here wsgi.py import os, sys sys.path.append('/home/app/myapp/sivale') sys.path.app...
Arturo Alm
1

votes
1

answer
597

Views

GeoDjango GDALException - OGR failure

After installing GeoDjango, I wanted to create a 'Location' object in the admin panel which uses an address and a point on a map. After submitting the form, I get an error like so... GDALException at /admin/maps/location/add/ OGR failure. I have tried looking at similar questions, like here, but non...
jayt
1

votes
0

answer
171

Views

Python Spyne XML GET (not POST)

I am creating a simple Web Service using Spyne, the client (which I don't control) send a GET to verify that SSL is up and working. The Spyne service I created responds with an error, saying only POSTS are supported. Any ideas on how I can make it respond to a simple get on the same path? Example of...
bcb
1

votes
1

answer
395

Views

Cannot send email using django and nginx(gunicorn) on digital ocean droplet

I deployed a website using django + nginx + gunicorn on a ubuntu droplet. And I use the email function of django. However, every time I tried to send email, I got a 502 error in my website. And my nginx error log is: [error] 24933#24933: *30944 upstream prematurely closed connection while reading re...
Owen
1

votes
1

answer
12

Views

Django should I manage users in a separate startapp?

In Django 2.2, if I plan to make authentication its own service in the future and serve requests through DRF, should I put my User model in a separate app from my regular 'functional apps'? There's no way each app should contain its own implementation of auth, right? Project_Root |--app_auth |--app_...
0

votes
2

answer
11

Views

how to receive username with token by django rest authetication?

I am using django Django=2.1.7 and rest framework djangorestframework=3.9.2 This is my url for login path('rest-auth/login', include('rest_auth.urls')), When I enter username and password I got the token from rest API. But I want my user detail like name, id etc to show in my react components. Pleas...
imsaiful
0

votes
0

answer
14

Views

Unable to send password reset email in Django

I am trying to reset the password, everything works but not sending email, what am i doing wrong here. urls.py from django.contrib import admin from django.contrib.auth import views as auth_views from django.urls import path, include from django.conf import settings from django.conf.urls.static imp...
user11057287
0

votes
0

answer
3

Views

Django+PostgreSQL Not Able to Fin Object From DB Right After Create It

I was testing User creation by creating a TestCase, and it couldn't be found right after created it. I've tried to flush cache by calling .refresh_from_db(), but it doesn't work. Here is my TestCase: class SuperStrangeTest(TestCase): def test_super_strange(self): john = User.objects.create() john.re...
Cai
0

votes
0

answer
7

Views

homepage link sends to about/about page unable to get home

I am trying to go back to my home page which is local host. however when trying to link to home using some python script it sends me to my forum page. Even stranger my forum page is at forum/forum/. while using an html href srcipt though it goes back to home. also loads in home. whats going on? im u...
Cameron Locke
1

votes
1

answer
1k

Views

ModuleNotFoundError: No module named 'mysite'

I have setup Python, Django and MySQL on my Windows machine. I'm trying to verify my database connection by running the following from a directory named 'zibit': > myvenv\Scripts\activate > set DJANGO_SETTINGS_MODULE=mysite.settings > django-admin dbshell After running the last command I get this e...
PhoenixDown
1

votes
2

answer
101

Views

Django Model serving Media Files

I have two models: Packages and Images. Images has many to one relation with Packages. Images table has a foreign key package_id. I have to display the attributes country, price of Packages with one image related to the package. There can be many images related to a single package however, I have to...
Shekhar Khatri
1

votes
0

answer
60

Views

Django Model Design (Big model vs multiple)

I have a question about designing my models. Suppose I have a following model: class Comment(models.Model): who = models.ForeignKey(User, on_delete=models.CASCADE) created = models.DateTimeField(auto_now_add=True) text = models.CharField(max_length=1000) likes = models.IntegerField(default=0) parent...
Meemaw
1

votes
1

answer
150

Views

Django authenticate method not working

I am trying to use the default Django from django.contrib.auth authenticate() method to authenticate if the user exists. I am doing this right after the user registers. The user registers and their username, email, and password is inputted into the database, but when I call authenticate(username=use...
Bytes
1

votes
0

answer
87

Views

How to use formatvalue filter for field in form template?

In Django templates, we use the filter on value fields such as {{value | formatvalue}} I want to generate my form dynamically like the example below. {% for field in form %} {{ field }} {% endfor %} As you know, the field attribute will be generated as an html element. Is there a way to add a filter...
Harun ERGUL
1

votes
1

answer
44

Views

Can't authenticate users in Django app

I'm trying to make a website using Django, and I have several views that require logins. However, I can't figure out how to authenticate users. I'm extremely new to web development (this is my first project), so please ask follow-up questions if I am not being clear. Here is some code that might pro...
Daanish Ahmed
1

votes
0

answer
149

Views

How to Trigger Browser Refresh when Django Static Files Change

I'm building a Django/React app and trying to automatically refresh the page whenever static files change (e.g. webpack bundle that's generated whenever React code is updated). I've tried the following packages: python-livereload, django-livereload, and django-livereload-server. None worked. And, th...
lgants
1

votes
0

answer
401

Views

Unable to send Activation Email with Djoser in Django Rest Framework

am trying to send activation email when a user get registered . when post request is called the content of email is shown in console but it is not send to user email. Django setting : EMAIL_USE_TLS=True EMAIL_HOST='smtp.gmail.com' EMAIL_HOST_USER= EMAIL_HOST_PASSWORD= EMAIL_PORT=587 EMAIL_BACKEND =...
Bishnu Sharma

View additional questions