Python Django应用程序赢得';t在服务器上保存新数据(URL)
当我在本地启动应用程序时,它可以正常工作。该应用程序只需提交新链接并更新产品的价格。这是应用程序从本地到服务器的链接。我需要更换服务器吗 也许我在保存选项上做错了Python Django应用程序赢得';t在服务器上保存新数据(URL),python,django,heroku-api,Python,Django,Heroku Api,当我在本地启动应用程序时,它可以正常工作。该应用程序只需提交新链接并更新产品的价格。这是应用程序从本地到服务器的链接。我需要更换服务器吗 也许我在保存选项上做错了 **this is the views.py code:** form = AddLinkForm(request.POST or None) if request.method == 'POST': try: if form.is_valid(): form.save() e
**this is the views.py code:**
form = AddLinkForm(request.POST or None)
if request.method == 'POST':
try:
if form.is_valid():
form.save()
except AttributeError:
error = "Uopa...ne mogu dohvatit ime ili cijenu"
except:
error = "Uopa...nesto je poslo po krivu"
form = AddLinkForm()
qs = Link.objects.all()
items_no = qs.count()
if items_no > 0:
discount_list = []
for item in qs:
if item.old_price > item.current_price:
discount_list.append(item)
no_discounted = len(discount_list)
context = {
'qs' : qs,
'items_no' : items_no,
'no_discounted' : no_discounted,
'form' : form,
'error' : error,
}
return render(request, 'links/main.html', context)
**and this is the models.py**
**this is the views.py code:**
form = AddLinkForm(request.POST or None)
if request.method == 'POST':
try:
if form.is_valid():
form.save()
except AttributeError:
error = "Uopa...ne mogu dohvatit ime ili cijenu"
except:
error = "Uopa...nesto je poslo po krivu"
form = AddLinkForm()
qs = Link.objects.all()
items_no = qs.count()
if items_no > 0:
discount_list = []
for item in qs:
if item.old_price > item.current_price:
discount_list.append(item)
no_discounted = len(discount_list)
context = {
'qs' : qs,
'items_no' : items_no,
'no_discounted' : no_discounted,
'form' : form,
'error' : error,
}
return render(request, 'links/main.html', context)
**and this is the models.py**
def __str__(self):
return str(self.name)
class Meta:
ordering = ('price_difference', '-created')
def save(self, *args, **kwargs):
name, price = get_link_data(self.url)
old_price = self.current_price
if self.current_price:
if price != old_price:
diff = float(price) - float(old_price)
self.price_difference = round(diff, 2)
self.old_price = old_price
self.current_price = price
else:
self.old_price = 0
self.price_difference = 0
self.name = name
self.current_price = price
super().save(*args, **kwargs)