Questions tagged [django-2.1]

Django 2.1 is a version of the Django framework, released August 2018. Please only use this tag if your question relates specifically to this version.

Django 2.1 works with Python 3.5, 3.6, and 3.7. Django 2.0 is thus the last version that worked with Python 3.4.

release notes

245 questions
27
votes
5 answers

Django cannot import login from django.contrib.auth.views

I try to build a login function for my page. To edit the urls.py as followed, it keeps printing this: cannot import name 'login' from 'django.contrib.auth.views' How could I deal with the problem? from django.contrib.auth.views import login from…
Thomas.Q
  • 377
  • 1
  • 4
  • 12
22
votes
3 answers

Adding indexes to model fields in Django with migrations

I am trying to add indexes on model fields using Field.db_index for an app that has migrations. Looking at Django's documentation all I need to do is to set db_index=True: class Person(models.Model): first_name = models.CharField() last_name…
Nima
  • 3,129
  • 1
  • 21
  • 20
17
votes
2 answers

Is it correct to modify old migration files in Django?

I'm trying to migrate my Django project from Python 2.7/Django 1.11 to Python 3.7/Django 2.1. And I'm a little bit confused with one issue. Django 2.1 marks as errors all models.ForeignKey(...) code strings in my project with: TypeError: __init__()…
kostr22
  • 576
  • 7
  • 27
8
votes
2 answers

Change Django autocomplete_fields label

I'm trying to set a custom label for all of the items of a type in autocomplete_fields. Until now, for a drop-down list, one would use ... class CustomDisplay(forms.ModelChoiceField): def label_from_instance(self, obj): return "Some…
Dorinel Panaite
  • 492
  • 1
  • 6
  • 15
7
votes
1 answer

namespace with router.urls in django2

In django2.1.5 and DRF 3.9.1, I am trying to add router.urls namespace which doesn't work. path('api/v2/', include(router.urls, namespace="v2")) The error in my terminal is "Specifying a namespace in include() without providing an app_name…
7
votes
2 answers

How to redirect url from middleware in Django?

How to redirect url from middleware? Infinite loop problem. I intend to redirect the user to a client registration url if the registration has not yet been completed. def check_user_active(get_response): def middleware(request): response…
marcelo.delta
  • 2,730
  • 5
  • 36
  • 71
7
votes
2 answers

How to manage a dynamic menu with Django?

I would like to create the links of the menu dynamically based on the Category models. I've used DetailView and ListView for create a list and detail page of a single category and it run fine. Now I would like to see in base.html a new link in a…
MaxDragonheart
  • 1,117
  • 13
  • 34
6
votes
1 answer

Problem with ERR_TOO_MANY_REDIRECTS django 2.1

I started to create login module in django. Login module is ok but I have problem with logout. When i click Logout - we see "error -ERR_TOO_MANY_REDIRECTS" Probably something in this file is incorect: account/urls.py from django.conf.urls import…
Martix
  • 143
  • 1
  • 6
5
votes
3 answers

TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names() - Django 2.1

I´m trying to log in a user without password using Django, until now I have created this: Nopassword.py class PasswordlessAuthBackend(ModelBackend): def authenticate(self, username=None): try: return…
Antonio Sanchez
  • 381
  • 1
  • 3
  • 11
5
votes
1 answer

django.db.utils.ProgrammingError: syntax error at or near "WITH ORDINALITY" LINE 6:

I am getting error while making migrate on django 2.1 application from django.db import migrations, models import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ ('sawy', '0005_auto_20190418_0607'), …
Saurabh Chandra Patel
  • 12,712
  • 6
  • 88
  • 78
5
votes
1 answer

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,…
CodeSpent
  • 1,684
  • 4
  • 23
  • 46
4
votes
1 answer

what are the differences between urls.py in project's folder and app folder in django?

In django there is a concept that makes me dazzled a bit.Why we should make a urls.py in our app folder while we have one in project folder. what is the specific job each one do ? how both have relation with each other e.g how do they interact with…
user12206273
4
votes
1 answer

Django Migration from 2.0 to 2.2(View Permissions Issue)

While Migrating the Django Facing issue related to migration : python manage.py migrate demo --database demo Getting Error related to : ValueError: Cannot assign "ContentType: ContentType object (1)": the current database router prevents this…
4
votes
3 answers

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…
Loonb
  • 1,068
  • 5
  • 18
  • 30
4
votes
1 answer

django.db.utils.IntegrityError: FOREIGN KEY constraint failed while executing LiveServerTestCases through Selenium and Python Django

I can run all unit tests successfully, I can even run selenium tests successfully if I run an independent server, but when I try to use LiveServerTestCases to test everything in a self-contained manner, each LiveServerTestCase test ends with the…
1
2 3
16 17