HttpResponseRedirect无法在回送请求中找到查询部分会话未保存键/值

时间:2018-09-13 19:45:04

标签: django session session-cookies httpresponse django-settings

我正在尝试重定向到另一个API以生成一些随机令牌,最终最终将再次循环回到我当前的URL,但是当重定向的URL实际上循环回到该函数时,我无法找到{{1 }}在QUERY_STRING中。

在中间状态下,我可以看到查询部分。中间状态如下(我通过给出print语句找到):

request.META

在views.py中:

https://mysite.domain.com/api/home/?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6qh

我的settings.py:

def home(self, request):
    print("\nMeta: ", request.META) 
    # Prints -> 
    # Meta: {'HTTP_ACCEPT': 'application/json, text/plain, */*', 'HTTP_CONNECTION': 'keep-alive', 'REMOTE_ADDR': 'xx.xx.xx.xxx', 'HTTP_ORIGIN': 'https://mysite.domain.com', 'CONTENT_LENGTH': '', 'QUERY_STRING': '', 'wsgi.multithread': False, 'uwsgi.node': b'ip-xx-xx-xx-xx.aws.test.domain.com', 'wsgi.input': <uwsgi._Input object at 0x7f965c42b3a8>, 'CONTENT_TYPE': '', 'wsgi.multiprocess': False, 'REQUEST_METHOD': 'GET', 'SCRIPT_NAME': '', 'REMOTE_PORT': '62724', 'REQUEST_SCHEME': 'https', 'SERVER_PROTOCOL': 'HTTP/1.1', 'SERVER_NAME': 'mysite.domain.com', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate, br', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.9', 'wsgi.errors': <_io.TextIOWrapper name=2 mode='w' encoding='ANSI_X3.4-1968'>, 'REQUEST_URI': '/dboardrpt/', 'HTTP_HOST': 'mysite.domain.com', 'DOCUMENT_ROOT': '/etc/nginx/html', 'wsgi.file_wrapper': <built-in function uwsgi_sendfile>, 'HTTP_REFERER': 'https://mysite.domain.com/api/home', 'wsgi.version': (1, 0), 'wsgi.url_scheme': 'https', 'HTTPS': 'on', 'uwsgi.version': b'2.0.14', 'SERVER_PORT': '443', 'wsgi.run_once': False, 'PATH_INFO': '/home/'}

    # Where the `QUERY_STRING` is blank, and that why the below if statement is failing.

    if (request.GET.get('token')):
        ...
        # Business logic follows....
        ...
    else:
        URL = "https://authenticate.domain.com/api/get-new-token/"
        params = {
          'redirect_uri': "https://mysite.domain.com/api/home/",
          'secret_key': settings.SECRET_KEY
        }
        return (URL + HttpResponseRedirect + '?' + urlencode(params))

查询部分没有以某种方式保存在会话中。我尝试过INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'corsheaders', 'rest_framework', ] MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies" 来同步python manage.py migrate表。

不确定我是否缺少django_session

中的某些内容

0 个答案:

没有答案