Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django查询字符串在会话期间保留在url中_Python_Django_Url - Fatal编程技术网

Python Django查询字符串在会话期间保留在url中

Python Django查询字符串在会话期间保留在url中,python,django,url,Python,Django,Url,我通过如下表单传递查询字符串: <form action="stockChart" autocomplete="off" method="GET"> <input type="text" required="required" name="Ticker" maxlength="5"> </form>

我通过如下表单传递查询字符串:

<form action="stockChart" autocomplete="off" method="GET">
  <input type="text" required="required" name="Ticker" maxlength="5">
</form> 

           
但是如果我转到另一个选项卡,在那里我还想使用同一个ticker,它就不起作用了,因为URL中没有查询字符串。 现在我正在使用TICKER=request.session['TICKER'],但这样做URL就不包含查询字符串。导航到其他页面时,是否有办法将字符串(?Ticker?AAPL)保留在url中?

不完全确定“如果我转到其他选项卡”的含义

假设您正在另一个选项卡中访问URL
/stockChart
,并希望它显示您最后的输入
股票代码
,您可以在视图中执行此操作:

  • 如果
    request.GET['Ticker']
    有值,请将其保存到
    request.session['Ticker']
    并显示页面
  • 如果缺少
    request.GET['Ticker']
    request.session['Ticker']
    包含数据,请重定向到
    '/stockChart?Ticker={}。格式(request.session['Ticker'])
  • views.py
         def stockChart(request):
             TICKER = request.GET['Ticker'].upper()