0
我是Django的新手,我想知道如何使用URL(或任何其他方式)將信息從一個網頁發送到另一個網頁。我試着做一個全局變量並返回信息,但它不起作用。在這個例子中,當按下提交按鈕時,我需要將發佈的數據quote
發送到下一頁。使用Django URL將發佈的信息發送到另一頁
這裏是我的模型:
from django.db import models
class OrderEntry(models.Model):
quote_num = models.CharField(max_length=50, primary_key=True)
customer = models.CharField(max_length=100)
cust_po = models.CharField(max_length=50)
datetime = models.DateTimeField(auto_now=True, editable=True)
形式:
from django import forms
class Details(forms.Form):
quote_number = forms.CharField(max_length=50, min_length=3)
customer = forms.CharField(max_length=100)
po_number = forms.CharField(max_length=50, min_length=4)
查看:
from django.shortcuts import render
from django.http import HttpResponseRedirect, HttpResponse
from orders.models import OrderEntry, Items
from orders.forms import Details, ItemDetails
def entry(request):
if request.method == 'POST':
form = Details(request.POST)
if form.is_valid:
customer = request.POST.get('customer')
quote = request.POST.get('quote_number')
purchase = request.POST.get('po_number')
obj_oe = OrderEntry(customer = customer, quote_num = quote,
cust_po = purchase)
obj_oe.save()
return HttpResponseRedirect('/entry/items')
else:
form = Details(
initial={'quote_number': 'QS', 'po_number': 'PO-'}
)
return render(request, 'order.html', {'form': form})
def entry_items(request):
if request.method == 'POST':
form = ItemDetails(request.POST)
if form.is_valid:
# quote = quote value
a1 = request.POST.get('i1')
a2 = request.POST.get('i2')
a3 = request.POST.get('i3')
a4 = request.POST.get('i4')
a5 = request.POST.get('i5')
a6 = request.POST.get('i6')
a7 = request.POST.get('i7')
a8 = request.POST.get('i8')
a9 = request.POST.get('i9')
a10 = request.POST.get('i10')
obj_oi = Items(quote_num = quote, item_1 = a1, item_2 = a2, item_3 = a3, item_4 = a4,
item_5 = a5, item_6 = a6, item_7 = a7, item_8 = a8, item_9 = a9,
item_10 = a10)
obj_oi.save()
return HttpResponseRedirect('/entry')
else:
form = ItemDetails
return render(request, 'order_items.html', {'form': form})
最後,網址:
from django.conf.urls import url
from django.contrib import admin
from orders import views_orders
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^entry/$', views_orders.entry),
url(r'^entry/items', views_orders.entry_items),
]
那麼如何將quote
的值轉換爲下一頁中的變量?
感謝您的幫助。