Cannot Import Name LoginView
Question:
I am trying to create a modal form in my django project. I am trying to use bootstrap modal forms and I am following an example:
https://pypi.org/project/django-bootstrap-modal-forms/
When I import in views.py:
from bootstrap_modal_forms.generic import BSModalCreateView
I get an error “cannot import name LoginView” – but I’m confused because I do not have LoginView anywhere in my project. Why is this happening? This is my first time trying to use Class Based Views. I know this isn’t a lot of detail, but I am completely confused here.
views.py
from django.urls import reverse_lazy
from .forms import BookForm
from .models import Book
from bootstrap_modal_forms.generic import BSModalCreateView
class BookCreateView(BSModalCreateView):
template_name = 'examples/create_book.html'
form_class = BookForm
success_message = 'Success: Book was created.'
success_url = reverse_lazy('index')
forms.py
from .models import Book
from bootstrap_modal_forms.forms import BSModalForm
class BookForm(BSModalForm):
class Meta:
model = Book
fields = ('title', 'author', 'price')
Answers:
You are using a version of Django (1.10) that is incompatible with the version of bootstrap_modal_forms
that you have installed. bootstrap_modal_forms
is attempting to import django.contrib.auth.views.LoginView
, which was only added in Django 1.11.
You will need to upgrade to at least Django 1.11 if you want to use bootstrap_modal_forms
. You should probably do this anyway given that 1.10 reached end of life a long time ago, and not secure.
Please check your Django asset folder tipically named "static/js" in the root’s folder. For any reasons when you do "pip install django-bootstrap-modal-forms" the folder is not filled from the needed two files that are jquery.bootstrap.modal.forms.js and jquery.bootstrap.modal.forms.min.js. So the solutions is:
- create the Django asset folder as for example "static/js"
- create the 2 empty files jquery.bootstrap.modal.forms.js and jquery.bootstrap.modal.forms.min.js
- go to the Github repository of the Django plugin and copy and past the content of 2 files. This is the GH link
I hope this help you
I am trying to create a modal form in my django project. I am trying to use bootstrap modal forms and I am following an example:
https://pypi.org/project/django-bootstrap-modal-forms/
When I import in views.py:
from bootstrap_modal_forms.generic import BSModalCreateView
I get an error “cannot import name LoginView” – but I’m confused because I do not have LoginView anywhere in my project. Why is this happening? This is my first time trying to use Class Based Views. I know this isn’t a lot of detail, but I am completely confused here.
views.py
from django.urls import reverse_lazy
from .forms import BookForm
from .models import Book
from bootstrap_modal_forms.generic import BSModalCreateView
class BookCreateView(BSModalCreateView):
template_name = 'examples/create_book.html'
form_class = BookForm
success_message = 'Success: Book was created.'
success_url = reverse_lazy('index')
forms.py
from .models import Book
from bootstrap_modal_forms.forms import BSModalForm
class BookForm(BSModalForm):
class Meta:
model = Book
fields = ('title', 'author', 'price')
You are using a version of Django (1.10) that is incompatible with the version of bootstrap_modal_forms
that you have installed. bootstrap_modal_forms
is attempting to import django.contrib.auth.views.LoginView
, which was only added in Django 1.11.
You will need to upgrade to at least Django 1.11 if you want to use bootstrap_modal_forms
. You should probably do this anyway given that 1.10 reached end of life a long time ago, and not secure.
Please check your Django asset folder tipically named "static/js" in the root’s folder. For any reasons when you do "pip install django-bootstrap-modal-forms" the folder is not filled from the needed two files that are jquery.bootstrap.modal.forms.js and jquery.bootstrap.modal.forms.min.js. So the solutions is:
- create the Django asset folder as for example "static/js"
- create the 2 empty files jquery.bootstrap.modal.forms.js and jquery.bootstrap.modal.forms.min.js
- go to the Github repository of the Django plugin and copy and past the content of 2 files. This is the GH link
I hope this help you