Python 在nginx和uwsgi网站中获取查询字符串

Python 在nginx和uwsgi网站中获取查询字符串,python,nginx,server,uwsgi,Python,Nginx,Server,Uwsgi,我用python、uwsgi和nginx构建了一个非常小的站点。当我在web浏览器地址栏中键入localhost:8080时,会显示类似“hello world”的内容 接下来我将添加查询字符串处理,但不知道如何添加。例如,我希望在命令提示符中打印查询字符串。因此,地址应该是这样的localhost:8080?abc&id=21&price=778,查询字符串应该是这样的abc&id=21&price=778 我不能成功。这是输出和代码: (myappenv) gameboy@localhost

我用python、uwsgi和nginx构建了一个非常小的站点。当我在web浏览器地址栏中键入
localhost:8080
时,会显示类似“hello world”的内容

接下来我将添加查询字符串处理,但不知道如何添加。例如,我希望在命令提示符中打印查询字符串。因此,地址应该是这样的
localhost:8080?abc&id=21&price=778
,查询字符串应该是这样的
abc&id=21&price=778

我不能成功。这是输出和代码:

(myappenv) gameboy@localhost:~/Dropbox/PycharmProjects/digitalOApp$ uwsgi --ini digitalOApp.ini
[uWSGI] getting INI configuration from digitalOApp.ini
*** Starting uWSGI 2.0.14 (64bit) on [Mon Feb  6 04:54:51 2017] ***
compiled with version: 4.9.2 on 03 February 2017 02:52:59
os: Linux-3.16.0-4-amd64 #1 SMP Debian 3.16.39-1 (2016-12-30)
nodename: localhost
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /home/gameboy/Dropbox/PycharmProjects/digitalOApp
detected binary path: /home/gameboy/Dropbox/PycharmProjects/digitalOApp/myappenv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 15353
your memory page size is 4096 bytes
detected max file descriptor number: 65536
lock engine: pthread robust mutexes
thunder lock: enabled
uwsgi socket 0 bound to UNIX address /home/gameboy/Dropbox/PycharmProjects/digitalOApp/digitalOApp.sock fd 3
uwsgi socket 1 bound to TCP address :8080 fd 4
Python version: 3.4.2 (default, Oct  8 2014, 10:47:48)  [GCC 4.9.1]
Python main interpreter initialized at 0x17461e0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 436608 bytes (426 KB) for 5 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x17461e0 pid: 14147 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 14147)
spawned uWSGI worker 1 (pid: 14148, cores: 1)
spawned uWSGI worker 2 (pid: 14149, cores: 1)
spawned uWSGI worker 3 (pid: 14150, cores: 1)
spawned uWSGI worker 4 (pid: 14151, cores: 1)
spawned uWSGI worker 5 (pid: 14152, cores: 1)
None
[pid: 14148|app: 0|req: 1/1] 127.0.0.1 () {36 vars in 646 bytes} [Mon Feb  6 04:55:14 2017] GET /?a=hej => generated 41 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 0)
None
[pid: 14151|app: 0|req: 1/2] 127.0.0.1 () {36 vars in 620 bytes} [Mon Feb  6 04:55:16 2017] GET /favicon.ico => generated 41 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 0)
wsgi.py:

import os, sys

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    print(os.getenv("QUERY_STRING"))
    h1 = "<h1 style='color:blue'>Hello There!</h1>"
    return(bytes(h1, 'utf-8'))
nginx:

(myappenv) gameboy@localhost:~/Dropbox/PycharmProjects/digitalOApp$ sudo cat /etc/nginx/sites-enabled/digitalOApp
[sudo] password for gameboy: 
server {
    listen 80;
    server_name localhost;

    location / {
        include         uwsgi_params;
        uwsgi_pass      unix:/home/gameboy/Dropbox/PycharmProjects/digitalOApp/digitalOApp.sock;
    }
}


(myappenv) gameboy@localhost:~/Dropbox/PycharmProjects/digitalOApp$ 
替换

print(os.getenv("QUERY_STRING"))
…与:

print(environ['QUERY_STRING'])
print(environ['QUERY_STRING'])