如何使用django

时间:2018-03-01 12:20:18

标签: python html django jinja2

我有一个使用jinja显示列表的html页面。 我希望能够让用户单击一个按钮,列表将被添加到数据库中。我已经将按钮放在一个表格中,并将其链接到我的网址,然后调用一个函数。

HTML:

<form method='post' action='../../accounts/myaccount/' name= '{{item}}'>
                                {% csrf_token %}
                                <a name = '{{ item }}'><button type='submit' class='btn'><img src={% static 'results/images/basket_02.png' %} alt='Image cannot be displayed right now'></button></a>
                            </form>

查看:

def myaccount(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            product = request.GET.get('name')
            print('product: ' , product)
            return render(request, 'signup/myaccount.html')

调用该函数并打印:product:NONE,而我希望将产品设置为列表。 我知道如何在我的视图中添加到数据库,但有没有办法实际访问我的列表?

1 个答案:

答案 0 :(得分:1)

您需要使用输入标记。

    Sub Convert()

    Dim cell As Range

    Dim sCode As String      'Securtiy code
    Dim symbol As String     'Symbol
    Dim receiveDate As Date  'Date
    Dim bidNum As Double    'Bid
    Dim askNum As Double    'Ask
    Dim closeNum As Double  'Close
    Dim sDesc As String      'Security Desc
    Dim cusip As String      'Cusip
    Dim cur As String        'Currency
    Dim pFactor As String    'Principal Factor


    Dim result As String     'Final result

    delim = "++^||"

    NumRows = Range("A2", Range("A2").End(xlDown)).Rows.Count

    Dim arrResult() As Variant
    ReDim arrResult(Range("A2", Range("A2").End(xlDown)).Rows.Count)

    Range("A2").Select
    c = 2

    For x = 1 To NumRows

        '============ c is row ==========

        sCode = Cells(c, 1)
        symbol = Cells(c, 2)
        receiveDate = Cells(c, 3)
        bidNum = Cells(c, 4)
        askNum = Cells(c, 5)
        closeNum = Cells(c, 6)
        sDesc = Cells(c, 7)
        cusip = Cells(c, 8)
        cur = Cells(c, 9)
        pFactor = Cells(c, 10)

        c = c + 1

        result = storeFun(sCode, symbol, receiveDate, bidNum, askNum, closeNum, sDesc, cusip, cur, pFactor)
        arrResult(x - 1) = result

        ActiveCell.Offset(1, 0).Select

    Next

cell(12, 1) = arrResult(2)

End Sub

Function storeFun(sCode, symbol, receiveDate, bidNum, askNum, closeNum, sDesc, cusip, cur, pFactor) As String

Dim strDate As String
Dim strbidNum As String
Dim straskNum As String
Dim strcloseNum As String
Dim delim As String      '"++^||"

strDate = Format(receiveDate, "dd-mmm-yyyy")
strbidNum = Format(bidNum, "00.00000000")
straskNum = Format(askNum, "00.00000000")
strcloseNum = Format(closeNum, "00.00000000")

delim = "++^||"
storeFun = sCode + delim + symbol + delim + strDate + delim + strbidNum + delim + straskNum + _
            delim + strcloseNum + delim + sDesc + delim + cusip + delim + cur + delim + pFactor + delim

End Function