django-views

Getting error : Object of type User is not JSON serializable in django python

元气小坏坏 提交于 2021-01-28 03:38:55
问题 i am new here in django python, when i am trying to get data, from 3 tables, i am getting error Object of type User is not JSON serializable , can anyone please help me why i am getting this error ? here i have added my views.py and models.py file views.py # views.py from tokenize import Token from django.contrib.auth import authenticate from rest_framework import status from rest_framework.exceptions import ValidationError from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_200_OK

How to pass variable in url to Django List View

雨燕双飞 提交于 2021-01-28 02:55:45
问题 I have a Django generic List View that I want to filter based on the value entered into the URL. For example, when someone enters mysite.com/defaults/41 I want the view to filter all of the values matching 41. I have come accross a few ways of doing this with function based views, but not class based Django views. I have tried: views.py class DefaultsListView(LoginRequiredMixin,ListView): model = models.DefaultDMLSProcessParams template_name = 'defaults_list.html' login_url = 'login' def get

NoReverseMatch at / list

一世执手 提交于 2021-01-28 01:17:24
问题 I tried get dynamic link Error: NoReverseMatch at / Reverse for 'new_single' with keyword arguments '{'pk': 1}' not found. 1 pattern(s) tried: ['single/'] Code: view: {% for new in news %} {{ new.id }} <h2><a href="{% url 'new_single' pk=new.id %}">{{ new.title }}</a></h2> {% endfor %} urls: urlpatterns = [ url(r'^$', views.news_list, name='news_list'), url(r'single/<int:pk>', views.new_single, name="new_single"), ] views: def new_single(request,pk): new=get_object_or_404(News,id=pk) return

How to pass variable in url to Django List View

╄→尐↘猪︶ㄣ 提交于 2021-01-27 22:01:36
问题 I have a Django generic List View that I want to filter based on the value entered into the URL. For example, when someone enters mysite.com/defaults/41 I want the view to filter all of the values matching 41. I have come accross a few ways of doing this with function based views, but not class based Django views. I have tried: views.py class DefaultsListView(LoginRequiredMixin,ListView): model = models.DefaultDMLSProcessParams template_name = 'defaults_list.html' login_url = 'login' def get

sending mail in django - issue with gmail smtp

我们两清 提交于 2021-01-27 18:43:36
问题 I own a simple portfolio website @ www.manojmj.com I have a contact form on the site where users can fill a form and send it to me via email Right now, I have configured my Gmail account for sending mails via django. I know the from address in the mail will be replaced by my own address as given in settings.py if I use gmail as my provider and there is no way around this. I am ok with this, but the real issue is that, while I'm running my project on localhost, the emails are being sent just

How to request GET parameters in templates for a list of files?(Django Zip File Download Issue)

爱⌒轻易说出口 提交于 2021-01-27 16:37:24
问题 I want to download all the single or multiple files created by the function by zipping them. The problem is with templates. Please suggest properly to pass the GET parameters for a list of files I got an error : FileNotFoundError at /test/ [Errno 2] No such file or directory: '[' This is the error for improperly placing the query string that is referring to the list of files. My views are as follows: def submit(request): def file_conversion(input_file,output_file_pattern,chunk_size): output

ValueError: invalid literal for int() with base 10:

拜拜、爱过 提交于 2021-01-27 13:14:59
问题 i am getting this value error, when i try to insert some data to django model. My python script is : from task.employeeDetails.models import EmployeeDetails def dumpdata(): userName = "John" designation = 'Software Engineer' employeeID = 2312 contactNumber = 9495321257 project = 'AOL' dateOfJoin = '2009-10-10' EmployeeDetails(userName,designation,employeeID,contactNumber,project,dateOfJoin).save() dumpdata() My models.py is class EmployeeDetails(models.Model): userName = models.CharField(max

Success_url in django RedirectView

廉价感情. 提交于 2021-01-27 12:00:01
问题 does somebody know, can I use SuccessMessageMixin with RedirectView? Because when I use it in my views: class CarRentView(SuccessMessageMixin,RedirectView): success_message = "Well done!" permanent = False query_string = True model = Car def get_redirect_url(self, *args, **kwargs): car = get_object_or_404(Car, pk=kwargs['pk']) car.rent=True car.save() return reverse('cars') there is nothing happend. And I've got another question - is there any way to 'block' car, which is rent for next user

Differences between RESTful API and urlpatterns router in Django

情到浓时终转凉″ 提交于 2021-01-27 06:58:24
问题 Am new to web developpement and wondering the differences between: Django Restful API and standard Django URL routers urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', views.index, name='Index'), url(r'^getvalue/$', views.get_points, name='Get Points'), url(r'^putvalue/$', views.put_points, name='Put Points'), ] What are the benefits of setting Django restful API when interacting with Javascript components since both are JSON sending URL ? 回答1: Before understanding this you have

how to override delete confirmation page in django admin site?

≡放荡痞女 提交于 2021-01-27 06:35:25
问题 In my django 1.4 project I have a requirement to override the delete confirmation page in admin site and also perform some additional task model.I found generic DeleteView, but not found any good help about how to use it. 回答1: To override admin default confirmation page, define your own admin/delete_confirmation.html (source on Github) template. For example: if you want to override confirmation page for model Book defined in the app Library , create file TEMPLATES_ROOT_DIRECTORY/admin/library