django-views

Django Autocomplete Light - “The results could not be loaded”

喜夏-厌秋 提交于 2020-07-09 14:01:04
问题 I'm using Django-autocomplete-light on a small application. The UI seems to work, and I can select from some visible values. The problem arises when I type one or more letters into the box. Normally it should filter/select the results, instead, I get the error "The results could not be loaded" (see picture). Seems like the jquery is working fine, except for not filtering when I type in the box. Happy to add more code, just not sure what I need to add yet. models.py class Encounter(models

global name 'get_user_model' is not defined

£可爱£侵袭症+ 提交于 2020-07-09 06:39:09
问题 NameError at /project/reset_password_confirm/MTQ-4c8-65d880f1c28996091226/ global name 'get_user_model' is not defined Request Method: POST Django Version: 1.9.1 Exception Type: NameError Exception Value: global name 'get_user_model' is not defined Exception Location: /root/django/studie/project/views.py in post, line 770 Python Executable: /usr/bin/python Python Version: 2.7.9 views.py from django.contrib.auth.models import User line 770: def post(self, request, uidb64=None, token=None, *arg

Django 'dict' object has no attribute 'user_id'

人盡茶涼 提交于 2020-07-08 04:57:45
问题 I get the following error 'dict' object has no attribute 'user_id' but not sure I understand the error. Since user_id is available from the queryset. Error happens at the last line of code users_who_played = UserEvent.objects\ .values('user_id')\ .annotate(total_season_points=Sum('points'))\ .filter(event__season_id=season.id)\ .order_by('-total_season_points')\ for i, user_who_played in enumerate(users_who_played): try: user = UserSeason.objects. get(user=user_who_played.user_id, season

Django 'dict' object has no attribute 'user_id'

五迷三道 提交于 2020-07-08 04:57:10
问题 I get the following error 'dict' object has no attribute 'user_id' but not sure I understand the error. Since user_id is available from the queryset. Error happens at the last line of code users_who_played = UserEvent.objects\ .values('user_id')\ .annotate(total_season_points=Sum('points'))\ .filter(event__season_id=season.id)\ .order_by('-total_season_points')\ for i, user_who_played in enumerate(users_who_played): try: user = UserSeason.objects. get(user=user_who_played.user_id, season

How to have user log in and registration on same page using django

北慕城南 提交于 2020-07-02 11:27:22
问题 Currently I have a user log in page and a user sign up page, how can I have both of these on one single page? Base.html: <!doctype html> <head> {% block head %} <title>base</title> {% endblock %} </head> <body> {% block body %} {% endblock %} </body> </html> signup.html: {% extends 'core/base.html' %} {% block head %} <title> Sign Up</title> {% endblock %} {% block body %} <h2>Sign up</h2> <form method="post"> {% csrf_token %} {{ form.as_p }} <button type="submit">Sign up</button> </form> {%

Django get_queryset return custom variables

元气小坏坏 提交于 2020-06-29 06:41:06
问题 Using users as an example I am trying to show how many users there are. get_context_data works totally fine but get_queryset does not. I know that it's not set up properly but I've been playing around with it for quite some days and something is just not clicking.. The main goal is to use the Dajngo-Filter form and then be able to get the updated number of user count. I've only found endless documentation on how to show the "list" of users. Which I have done but no documentation on how to

Django 3.0 images: Unable to display images in template

大兔子大兔子 提交于 2020-06-29 05:04:35
问题 I have model named Book in models.py file. And based on this model, a view has been created to display images as products. Which renders books(products) on shop.html template. Problem is that i am unable to get their cover images which are saved across each publishers id who is seller of those books. This is code of shop.html (in which i am trying to display image). <div class="container mt-4"> <div class="row"> {% for b in books|slice:":10" %} <div class="col-lg-2 col-md-3 col-sm-4"> <div

Django: all auth create account with email - unique constraint failed. Display message instead of giving an error

喜欢而已 提交于 2020-06-29 04:18:08
问题 I am using djnago all-auth to create custom user accounts. When creating an account with email and password, if account with a email already exits it gives an error (UNIQUE constraint failed: account_emailaddress.email) but I would like to display message that an account with this email already exists instead of throwing an error. What is the best way to handle this? In general I would use AJAX to verify and display message for my own views but I do not know how to deal here with django all

Ajax sending data twice in views.py django

早过忘川 提交于 2020-06-29 04:00:12
问题 I have this form in index.html and two submit button on clicking on one button named .graph-btn I m using jquery and ajax to send data from form to Django. Code: index.html <form action="{% url 'Graph' %}" method="post"> {% csrf_token %} <table class="table table-striped table-dark" cellspacing="0"> <thead class="bg-info"> <tr> <th>Company's Symbol</th> <th>Current Price</th> <th>View Current chart</th> <th>Action</th> </tr> </thead> <tbody> {% for a,b in stocks %} <tr> <th scope="row" class=

Django CBV CreateView - Redirect from CreateView to last page

ⅰ亾dé卋堺 提交于 2020-06-29 03:30:11
问题 I'm learning Django and i have problem with redirecting back from CreateView I want to redirect to a BookDetail page which contains list of bookinstances which are created by CreateView. models.py: class BookInstance(models.Model): """Model representing a specific copy of a book (i.e. that can be borrowed from the library).""" id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text='Unique ID for this particular book across whole library') book = models.ForeignKey('Book', on