django-views

How to send a request to another server in a django view?

我只是一个虾纸丫 提交于 2020-12-29 06:01:33
问题 I want to send an http request to another server in my django view like this: def django_view(request): response = send_request('http://example.com') result = do_something_with_response(response) return HttpResponse(result) How can I do that? 回答1: You can use python requests library to send the request and get the response. But you will need to format the response for your need. Here is an example of GET request: import requests def django_view(request): # get the response from the URL

How to send a request to another server in a django view?

戏子无情 提交于 2020-12-29 06:01:01
问题 I want to send an http request to another server in my django view like this: def django_view(request): response = send_request('http://example.com') result = do_something_with_response(response) return HttpResponse(result) How can I do that? 回答1: You can use python requests library to send the request and get the response. But you will need to format the response for your need. Here is an example of GET request: import requests def django_view(request): # get the response from the URL

how to use Django filtered class data to 2 seperate view

被刻印的时光 ゝ 提交于 2020-12-26 04:26:40
问题 I am using Django filter and using it in normal view it is working as expected now I want to download the filtered data so for this I am writing one download view where I am trying to use the same FilterClass but no luck. It is giving me an ERROR( Exception Value: type object 'CTSFilter' has no attribute 'values_list' ). Can anyone please help/suggest how to use filtered queryset in filter class more than one view OR pass the data of filtered query to the download views. Please find my code.

data doesn't appear in my html page when i add new record - Django

旧街凉风 提交于 2020-12-15 06:26:13
问题 when i add new record from admin panel it should appear in html page , but it doesn't do that how to fix it models.py : class BestArticals(models.Model): name = models.CharField(max_length=240) url = models.URLField(default="",max_length=240) image = models.ImageField(upload_to='images/',null=True, blank=True) def get_image(self): if self.image and hasattr(self.image, 'url'): return self.image.url else: return '/path/to/default/image' def __str__(self): return self.name views.py : from

object has no attribute 'object_list'

为君一笑 提交于 2020-12-15 05:40:08
问题 I am getting an error and I think it may be for the same reasons Viktor had a problem ('ProductList' object has no attribute 'object_list') On Viktors post AKS wrote - You might be getting the error on following line in get_context_data() of the super class: queryset = kwargs.pop('object_list', self.object_list) The get method of BaseListView sets the object_list on the view by calling the get_queryset method: self.object_list = self.get_queryset() But, in your case, you are calling get

GET products and images from two Django models, by filtering the product name and accessing the database only once

☆樱花仙子☆ 提交于 2020-12-15 05:23:39
问题 I have two Django models for an eCommerce website: class Product(models.Model): name=models.CharField(max_length=300) description=models.CharField(max_length=10000) class Thumnbnail(models.Model): thumnbnail=models.ImageField(null=True) product=models.ForeignKey(Product, related_name='related_product', on_delete=models.CASCADE) The user will input some keywords, and I filter on the product names with that keyword, and show only those products. With every product, on the results page, I want

GET products and images from two Django models, by filtering the product name and accessing the database only once

女生的网名这么多〃 提交于 2020-12-15 05:23:23
问题 I have two Django models for an eCommerce website: class Product(models.Model): name=models.CharField(max_length=300) description=models.CharField(max_length=10000) class Thumnbnail(models.Model): thumnbnail=models.ImageField(null=True) product=models.ForeignKey(Product, related_name='related_product', on_delete=models.CASCADE) The user will input some keywords, and I filter on the product names with that keyword, and show only those products. With every product, on the results page, I want

Dropdown select option to filter a Django list

…衆ロ難τιáo~ 提交于 2020-12-12 01:47:27
问题 Coming from Angular, this was easy to do, but I am not sure where to begin on creating a dropdown form that will filter from a list of objects. Basically, I have the code below, that will pull in and display all real estate listings; I would like to create a dropdown that will have 2 selections, 'Featured' and 'New Listing' and when a user selects one, the list will filter out and display only those listings that match. Thank you for your help. Here is my model from django.db import models

Dropdown select option to filter a Django list

我的未来我决定 提交于 2020-12-12 01:47:09
问题 Coming from Angular, this was easy to do, but I am not sure where to begin on creating a dropdown form that will filter from a list of objects. Basically, I have the code below, that will pull in and display all real estate listings; I would like to create a dropdown that will have 2 selections, 'Featured' and 'New Listing' and when a user selects one, the list will filter out and display only those listings that match. Thank you for your help. Here is my model from django.db import models

Django - download file from FileField()

人走茶凉 提交于 2020-12-06 16:52:57
问题 I'm struggling with the following problem. I have a database model with FileField() . models.py class InputSignal(models.Model): input_file = models.FileField(upload_to='signals/', null=False, ) A view that displays records from this table. It also supports deleting specific rows. views.py def storage_list(request): signals = InputSignal.objects.filter(author=request.user) if request.method == 'DELETE': id = json.loads(request.body)['id'] signal = get_object_or_404(InputSignal, id=id) signal