dqn48247 2016-09-03 23:57
浏览 51

如何根据用户输入的网站字段执行Python脚本

Using the following python.py file below as an example, how could a user on a website form select the position from something like a dropdown field or the user could input WR, RB, QB themselves. (position="WR" is currently what is in the code below) and click submit and the code will execute the query into a table?

I am using Wordpress on one server with MySQL. On another server, I am using Python and PostgreSQL. Thank you for any help you can provide.

import nfldb

db = nfldb.connect() q = nfldb.Query(db) q.game(season_year=2015, season_type='Regular') 
q.player(position="WR") 
q.play(receiving_rec=1)

def inside(field, stat):
        cutoff = nfldb.FieldPosition.from_str(field)
        return lambda play: play.yardline + getattr(play, stat) >= cutoff plays = filter(inside('OPP 20', 'receiving_yds'), q.as_plays())

for p in plays:
   print p
  • 写回答

1条回答 默认 最新

  • douxiaqin2062 2016-09-04 00:20
    关注

    I'm no expert, but be able to run code in response to any user interaction on your website, there should be some kind of web service running that would run your code. The general idea would be to first have the Wordpress server able to send out a "GET" to your postgre server, and be able to receive its answer. Then I would create a Web Service on your PostgreSQL (something like Flask would be just fine, if you want you have the excellent tutorial by Miguel Grinberg) so it can receive the request, run the code you mention and then send the response to the Wordpress+MySQL.

    Hope I'm pointing you in the right direction.

    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样