Questions tagged [django-2.1]

1

votes
1

answer
1.2k

Views

Django 2.1 SQL Server 17 error - isn't an available database backend. Try using 'django.db.backends.XXX'

django.core.exceptions.ImproperlyConfigured: 'django-pyodbc-azure' isn't an available database backend. Try using 'django.db.backends.XXX', where XXX is one of: 'mysql', 'oracle', 'postgresql', 'sqlite3' I have tried switching to the following DATABASE settings, with no luck. DATABASES = { 'default'...
Loser Coder
1

votes
2

answer
68

Views

Saving Nested data in using django serializer class

I have a json data to save to a django model. When i try to save it, i get all sorts of errors and i have tried to work around it, all to no avail. Please help me i am new to django rest framework. This are the models i am inserting into: class OrderItemDishItem(SoftDeleteModelBase): item = models.F...
Lawal Abimbola
1

votes
0

answer
73

Views

Adding command arguments to the Django runserver command and handle() method setup for local secure HTTP server

I'll keep this as vague as possible - as it's quite a broad question. I'm building a payment system within my Django project - and it would be amazing to be able to run my project over a secure server connections. And now were moving into a more forced secure internet with more emphasis on site sec...
1

votes
1

answer
26

Views

url encoded characters on clicking link and page not found

I am getting the following error using Django 2.1: Page not found (404) Request Method: POST Request URL: http://localhost:8000/user-accounts/%5Eregister/ Using the URLconf defined in my_project.urls, Django tried these URL patterns, in this order: admin/ user-accounts/ ^register/$ [name='registe...
codyc4321
1

votes
0

answer
90

Views

Django rest framework cache response in list method based on query_params

I am using django rest framework to model api views. I have an API ModelViewSet class which has two action methods: list() and retrieve() retrieve() method example: @method_decorator(never_cache) def retrieve(self, request, *args, **kwargs): # /en/api/v1/pair/ calls this method ... return Response(s...
Igoris Skinderis
1

votes
1

answer
143

Views

File Browser no grapelli: NameError: name 'site' is not defined

I'm following this tutorial for install django-tinymce4-lite. At the end of the tutorial there are the indications to install django-filebrowser-no-grappelli. I use Django 2.1.1 but even though I've followed all the indications, after the installation of the file browser was shown this message: File...
Massimiliano Moraca
1

votes
1

answer
34

Views

how can i check duplicate data in my django database comparing with form data in generic view(Updateview)

I made a Updateview method in Django to update firstname, lastname, mobile etc..but how can I check the data received by the generic view through the form is previously exist in DB. For example, I want to avoid duplicating of mobile number with the model User in the database I tried by approaching d...
nani raju
1

votes
1

answer
47

Views

Django 2.1 annotate count of child and grand child

I want to count how many child and grandchild each record has. These are my table structures bellow: Records: id | name 1 | record 1 Posts: id | record | title 1 | record 1 | title 1 2 | record 1 | title 2 Attachments: id | post | name 1 | post 1 | name 1 2 | post 1 | name 2 3...
Christopher
1

votes
0

answer
121

Views

Django: Download Excel after User Clicks a Button

In my Django project, I need to send an in-memory Excel file to the client side for download. The download should start after the user clicks a button. Here is my project structure: C:. │ db.sqlite3 │ manage.py │ Pipfile │ Pipfile.lock │ requirements.txt │ ├───app ...
Diana Smith
1

votes
2

answer
328

Views

Change url in Django

I am trying to load a pdf file in django which is already present in the database. I can access the pdf file using the url, 'localhost:8000/documents/file.pdf' but when I perform the query and return the response containing this file, url it redirects to 'localhost:8000/ans/documents/file.pdf' whic...
Tahseen Rahman
1

votes
1

answer
174

Views

'WSGIRequest' object has no attribute 'sessions' (Django 2.1.2)

I am working on a django web app and I need to use sessions and cookies. I wasn't getting this error before while using sessions and cookies but now It is happening again: AttributeError at /dashboard/ 'WSGIRequest' object has no attribute 'sessions' Request Method: GET Request URL: http://127.0....
snakebiking49
1

votes
1

answer
35

Views

When click change password is blank page but password was changed django

I create login page. My problem is with 'forgotten password'. User enter a mail and django send a message with link. When click on it must change password. When complet click on 'Change password' we should move on next page but it is blank. But password was changed. account/urls.py from django.urls...
Martix
1

votes
1

answer
91

Views

Django creating foreign key references to the wrong tables on database creation

I wiped out the database on my Django app to start again. I did this by deleting the database file and existing migrations and then re-running makemigrations and migrate. I of course backed up the database first. I soon ran into an issue; upon submitting a form I was informed that The table 'topics_...
STiGYFishh
1

votes
1

answer
21

Views

Unnecessary join in django queryset of model with many-to-many field and intermediate table

When I try to get all objects of my model FabricCategory, it returns some duplicates. I've found unnecessary LEFT OUTER JOIN in sql query: python manage.py shell_plus --print-sql >>> FabricCategory.objects.all() SELECT `product_fabriccategory`.`id`, `product_fabriccategory`.`price_impact`, `product_...
s.weszler
1

votes
1

answer
41

Views

With using login(request, user) function with a database other than default - Django?

With using login(request, user) function with a database other than default - Django? user = authenticate(username=username, password=password) login(request, user) Is there any possibility The request's session was deleted before the request completed. The user may have logged out in a concurrent r...
marcelo.delta
1

votes
0

answer
14

Views

How to create custom ACL functionality in Django 2.x?

I want to create custom ACl functionality in Django2.x Acl project structure below: C->Company R->Role (superuser, admin, manager etc.) U->User C1->r1,r2,r3->u1,u2,u3,u4,u5 C2->r1,r2,r3->u6,u7,u8,u9,u10 C3->r1,r2,r3->u11,u12,u13,u15,u15 How can i give the permission user to role wise for multiple co...
Masud Shaikh
1

votes
1

answer
16

Views

Select2 4.0.5 common errors in Django admin

(Disclaimer: this is a self-answered question) I wanted to set up some Select2 to my form fields while in a Django admin panel (specifically in the change_list.html template). So I added the neccesary scripts to the page (not the full version), but when it loads, I get this errors: Select2: An insta...
RompePC
1

votes
0

answer
26

Views

Django - Signal.disconnect does not disconnect the signal

I can't figure out why disconnect of post_save signal does not work in my project. When I call PipedriveSync.objects.first().sync_with_pipedrive(), it does something and then tries to save some information to the object. Then, the sync_pipedrivesync receiver is called which calls sync_with_pipedriv...
Milano
1

votes
1

answer
41

Views

User Registration: Creating user accounts Django 2.1.5

I'm having some trouble creating new accounts and then authenticating. I enter all the credentials in (username, password), and select 'submit', and it successfully redirects me back to the 'account successfully created page'. However i can't find the new user account in the database and on the staf...
Duke Sanmi
1

votes
0

answer
18

Views

How to show same message on each site page using middleware

I am new to django and programming. I'm trying to make an ecommerce web site and I am stuck on the custom middleware. I am trying set up a message which will appear on each page of site. I think the code is working because if I enter print('something') and refresh the browser 'something' is in the t...
Fleaboy Redhot
1

votes
2

answer
421

Views

Django Forms - Change widget attributes

I want to define a class attribute for the tags within a django ChoiceField, how can I do that? I tried to set the widget class, and specifying an attribute like so, in forms.py: field = forms.ChoiceField(choices=[(1, 'foo'), (2, 'bar')], widget=forms.Select(attrs={'class': 'form-control'})) And re...
drec4s
1

votes
2

answer
45

Views

Django - Reverse for 'list1' not found. 'list1' is not a valid view function or pattern name

I'm trying to upload a file, I got the code from some website. Which was written in older Django version and i'm using a latest version. Got some errors while running, fixed them by going through stackoverflow. But now i'm stuck with no clue with the error mentioned, this is my first Django project....
NMN
1

votes
1

answer
317

Views

Specifying a namespace in include() without providing an app_name is not supported

I am getting these error Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead. my code is shown below projectname.urls from django.contrib import...
Maruthesh
1

votes
1

answer
265

Views

How to pass username in kwargs of Django filter?

In the webapp, to retrieve all the objects from a specific user I am using user pk. But to make url more readable I want to use username. The problem is in the django view, user pk in kwargs giving the correct values, but when I use username it shows error. Here are my codes using 'username' as kwa...
Bidhan Majhi
1

votes
1

answer
64

Views

How to extract specific data in results obtained from using Python Requests library

Please take a look at the code below: @login_required def dashboard(request): code = request.GET.get('code', '') payload = { 'client_id' : settings.GITHUB_CLIENT_ID, 'client_secret' : settings.GITHUB_CLIENT_SECRET, 'code' : code, 'state' : settings.STATE, } response = requests.post('https://github.c...
Caspian
0

votes
1

answer
11

Views

Page not found, URL not resolved

I am trying to call a function in my views.py by pasting a url http://127.0.0.1:8000/upload_results/UniEX_HG1_A15 in the web browser, but the request fails and I can not see why my URL pattern does not work. The error: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:800...
MaxMueller83
1

votes
1

answer
0

Views

IntegrityError in TestCase runs after updating to Django 2.0

I upgraded from Django 1.11 to Django 2.0 and my tests started failing. I have 7 TestCase classes and all use the setUpTestData provided by Django. When I run them all together one of them fails to set up because of an psycopg2.IntegrityError: duplicate key value violates unique constraint 'doctors_...
Ysrninja
1

votes
1

answer
0

Views

Adding values to Django QuerySet

Is there any way to append a non-Django supplied value to a query? For instance, to find out if a store closed, I may run a function called get_closed_stores() which returns a list of closed stores. Stores Closed [00090, 00240, 00306, 00438, 03005, 05524] Great, now we have store numbers for stores...
CodeSpent
1

votes
3

answer
0

Views

Django Structures: Many apps VS one large app

I hope this is not a opinion based question but more like a solutions to a complicated django website. fyi, i am quite a beginner in django. first of all, i am doing a complicated accounting django website where there are features like: purchases (purchase order, quotation request, quotation, invoi...
Tian Loon
1

votes
1

answer
0

Views

Django 2.1 - linking user to related model

I am creating a Django project, and I want to create profiles of two different user types as a separate model. They will have a OneToOneField relationship with the logged-in user. class UserMusician(models.Model): ... class UserFan(models.Model): ... I have seen two different ways of doing this. One...
Burke
1

votes
1

answer
0

Views

Django - model mixin doesn't work as expected

In PipedriveSync model I use GenericForeignKey so any model can have PipedriveSync object related. class PipedriveSync(TimeStampedModel): ... content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_...
Milano
0

votes
0

answer
7

Views

How to save Foreign Key values in DJANGO REST?

Let's say i have models like follow. class Department(models.Model): name = models.CharField(max_length=255) class Student(models.Model): department = models.Foreignkey(Department, on_delete=models.CASCADE) name = models.CharField(max_length=255) Now i need to set Department(which is created already...
N.HariHaraSudhan
0

votes
0

answer
3

Views

django-widget-tweaks error while rendering in Django 2.1

While trying to use OSMField from django-osm-field and rending it with with django-widget-tweaks I am getting this error: File '/usr/local/lib/python3.7/site-packages/django/forms/boundfield.py', line 93, in as_widget renderer=self.form.renderer, TypeError: render() got an unexpected keyword argumen...
ketimaBU
1

votes
2

answer
31

Views

Combining more than one slug in the url

I'm trying to use two slug for generate the urls of a type of post. My site is divided in category and everyone of these have one or more post. views.py def singlePost(request, slug_post): blogpost = get_object_or_404(BlogPost, slug_post=slug_post) context = {'blogpost': blogpost} return render(requ...
1

votes
0

answer
27

Views

Use django-filters on multiple models

I'm trying to create a search capability in my Django project that will filter multiple models (currently 3). It worked great for one model, worked when I added a second, but when I tried to add a dropdown menu for the third model, I got an error saying they keyword was unavailable (because it wasn'...
Bird
0

votes
0

answer
3

Views

Retrieving An Entire Table from Database using Drop-Down Menu Django

I am trying to figure out how I can create a drop-down menu which can display an “entire table” from the Django database backend. Note, each item of the drop-down menu is simply a reference to the table from the database and so that when an item is selected from the menu it should display the t...
aBiologist
0

votes
0

answer
8

Views

Django app goes haywire when deployed. Race conditions?

I wrote a django app for quizzing, and it checks the user's answers and updates scores as soon as the user submits an answer. Here is the corresponding view to do this - def check_answer(request): current_user = request.user current_team = Team.objects.get(user = current_user) current_score = curre...
Dushyant Yadav
0

votes
0

answer
3

Views

Redirect old path to a new path on website based on Django

After the solution of my problem with double slug now I'm faced with one thing totally new for me. I've never worked with the redirection! In urls.py my old path was: path('/', views.singlePost, name='single_blog_post'), Now I've have this: path('//', views.singlePost, name='single_blog_post'), With...
0

votes
0

answer
4

Views

How to implement Depended Drop Down List in Django administrator?

I have multiple dropdown lists that depended on each other as below: Province-->City-->Bakhsh-->Dehestan-->Abadi my models are: from django.db import models # Create your models here. class Province(models.Model): id = models.CharField(primary_key=True, max_length=2) name = models.CharField(max_leng...
mehdi parastar
1

votes
1

answer
269

Views

How to pre-populate Django ModelForm fields

I have the following ModelForm: class IssueProcessForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(IssueProcessForm, self).__init__(*args, **kwargs) self.fields['number'].disabled = True self.fields['title'].disabled = True self.fields['body'].disabled = True self.fields['body'].wid...
Caspian

View additional questions