-1

Djangoビューにダウンロードリンクがあり、ユーザーはPDFフォームをダウンロードできます。ただし、リンクとともに渡されるすべてのURLパラメーターも取得する必要があります。

つまり、ユーザーがクリックした場合

http://www.abc.com/download次に、簡単なpdfフォームがダウンロードされます

しかし、私はクリックを使用します

http://www.abc.com/download?var1=20&var2=30&var3=40

次に、それらのパラメーターを名前とともに取得し、フィールドに入力する必要があります。

その引数は変化する可能性があるため、ビュー内の引数をハードコーディングすることはできません

4

1 に答える 1

4
def my_view(request):
    get_args = request.GET #dict of arguments from a get request (like your example)
    post_args = request.POST #dict of arguments from a post request
    all_args = requst.REQUEST #dict of arguments regardless of request type.

編集:あなたのコメントに基づいて、あなたはPythonに不慣れでなければなりません。

辞書の項目にアクセスする方法はいくつかあります。

#This method will throw an exception if the key is not in the dict.
get_args['var1'] #represents the value for that key, in this case '20'

#This method will return None if the key is not in the dict.
get_args.get('var2') #represents the value for that key, in this case '30'

または、dictをループすることもできます。

for key,val in get_args.items():
    do_something(val)
于 2012-12-10T05:31:59.327 に答える