django-2.0

Custom LoginView in Django 2

痴心易碎 提交于 2020-01-04 00:31:37
问题 I am trying to customise the authentication and view in Django 2 but the problem is that if the user is already authenticated the login form is still shown and it is not redirected to the appropriate URL. To get over this I have done the following: class CustomLoginView(LoginView): form_class = LoginForm template_name = 'login.html' def get_initial(self): if self.request.user.is_authenticated and self.request.user.is_staff and has_2fa(self.request.user): return HttpResponseRedirect(reverse('{

Heroku can't find my 'settings.py' file

纵饮孤独 提交于 2020-01-03 05:20:10
问题 After deploying my django project on heroku get this in logs: File "/app/django_structure/src/django_structure/wsgi.py", line 16, in <module> 2018-03-23T12:09:10.575053+00:00 app[web.1]: application = get_wsgi_application() 2018-03-23T12:09:10.575056+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application 2018-03-23T12:09:10.575058+00:00 app[web.1]: django.setup(set_prefix=False) 2018-03-23T12:09:10.575061+00:00 app[web.1]

Django 2, python 3.4 cannot decode urlsafe_base64_decode(uidb64)

纵然是瞬间 提交于 2019-12-31 10:39:10
问题 i am trying to activate a user by email, email works, encoding works, i used an approach from django1.11 which was working successfully. In Django 1.11 the following decodes successfully to 28, where uidb64 = b'Mjg' force_text(urlsafe_base64_decode(uidb64)) In django 2 (2, 0, 0, 'final', 0) the above code decode does not work and results in an error django.utils.encoding.DjangoUnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 1: invalid continuation byte. You passed in b'l

can not login with Extended AbstractBaseUser model

心不动则不痛 提交于 2019-12-25 10:05:09
问题 I'm using Django 2.0 I have extended the AbstractBaseUser to make some modification to the email and use email as username class UserManager(BaseUserManager): def create_user(self, email, password=None, is_staff=False, is_superuser=False): if not email: raise ValueError('User must have an email address') if not password: raise ValueError('User must have a password') user = self.model( email=self.normalize_email(email) ) user.is_staff = is_staff user.is_superuser = is_superuser user.set

django.core.exceptions.FieldError: Unknown field(s) specified by user

你说的曾经没有我的故事 提交于 2019-12-24 17:16:05
问题 I'm using Django 2.0 I have extended AbstractBaseUser model to create a custom User model. In my accounts/models.py class UserManager(BaseUserManager): def create_user(self, email, password=None, is_staff=False, is_admin=False, is_active=False): if not email: raise ValueError('User must have an email address') if not password: raise ValueError('User must have a password') user = self.model( email=self.normalize_email(email) ) user.is_staff = is_staff user.is_admin = is_admin user.is_active =

Python social-auth-app-django 'social' is not a registered namespace

北战南征 提交于 2019-12-23 05:45:13
问题 I'm working on a project with Python(3.6) and Django(2.0) in which I'm trying to integrate social login by using social-auth-app-django package. Managing users in the users app. Here's my configurations: From settings.py: INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'users', 'phone_field', 'social_django', ] MIDDLEWARE = [ 'django.middleware.security

“upstream prematurely closed connection while reading response header from upstream” Django, Ubuntu, Nginx, Gunicorn

南楼画角 提交于 2019-12-23 02:28:08
问题 I deployed a Django website using this tutorial https://jee-appy.blogspot.com/2017/01/deply-django-with-nginx.html The website can be accessed from the internet, www.simplesol.com When I try to make a POST request, it fails and I get a 502 error. In my nginx-error.log file I get this error message *344 upstream prematurely closed connection while reading response header from upstream, client: InternalIP, server: ExternalIP, request: "POST /audit/ HTTP/1.1", upstream: "http://unix:/home

Getting TypeError: __init__() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries

Deadly 提交于 2019-12-17 06:26:12
问题 I have two classes in my sqlite database, a parent table named Categorie and the child table called Article . I created first the child table class and addes entries. So first I had this: class Article(models.Model): titre=models.CharField(max_length=100) auteur=models.CharField(max_length=42) contenu=models.TextField(null=True) date=models.DateTimeField( auto_now_add=True, auto_now=False, verbose_name="Date de parution" ) def __str__(self): return self.titre And after I have added parent

Getting TypeError: __init__() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries

给你一囗甜甜゛ 提交于 2019-12-17 06:26:05
问题 I have two classes in my sqlite database, a parent table named Categorie and the child table called Article . I created first the child table class and addes entries. So first I had this: class Article(models.Model): titre=models.CharField(max_length=100) auteur=models.CharField(max_length=42) contenu=models.TextField(null=True) date=models.DateTimeField( auto_now_add=True, auto_now=False, verbose_name="Date de parution" ) def __str__(self): return self.titre And after I have added parent

How to make a queryset inside a queryset?

北城以北 提交于 2019-12-13 03:12:56
问题 I wan't to make a parent-child app in django. So, let me explain how i want this to work. I got a view where all humans are shown (parents and children). I click on any of them, so it opens a different view, where all of the children and parents are shown. I can click at any of them and see the same thing for everyone. It only worked (kinda) this way: class Parent(models.Model): ...(name, etc.) class Child(models.Model): ...(same fields) field = ForeignKey(Human, on_delete='CASCADE')