Hej, 我有一個網址問題。通過按鈕,我傳遞給URL適當的ID,在控制器中,我正在使用此ID並將其分配給當前日期以將其保存在數據庫中(與用戶的表然後管理員單擊「參加」並將lastAttendance保存在數據庫中) 。我點擊後與網址堆積在一起,因爲它不會將我重定向到同一頁面。任何意見讚賞!Django的網址。點擊按鈕並重定向到同一頁面
MODEL:
class Donor(models.Model):
firstName = models.CharField(max_length=50)
lastName = models.CharField(max_length=50)
bloodType = models.CharField(max_length=10)
createdDate = models.DateTimeField(auto_now_add=True)
lastAttendance = models.DateTimeField(auto_now_add=True)
URLS:
url(r'^donors/get?attend=(\d+)/$', views.donors, name='donors'),
VIEW:
@login_required(login_url="login/")
def donors(request):
global message
if request.method == 'POST':
form = PostForm(request.POST) # A form bound to the POST data
if form.is_valid():
form.save()
# context = RequestContext(request)
donor_id = None
if request.method == "GET":
donor_id = request.GET.get('id')
if donor_id:
donor = Donor.objects.get(id=int(donor_id))
if donor:
donor.lastAttendance = datetime.datetime.now()
donor.save()
#display all the lates added donors
query_results = Donor.objects.order_by('-createdDate')
#dislay total ammount of rows
donors_count = Donor.objects.count()
return render(request, 'donors.html', {
'form': PostForm(),
'donors_count': donors_count,
'query_results': query_results,
})
HTML:
<button
type="submit"
class="btn attendBtn"
value="{{ item.id }}"
name="attend">attend
任何幫助將不勝感激!
請出示模板 –