nginx上跑webpy网站,form提交数据时遇到了action的url跳转问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
paloalto

nginx上跑webpy网站,form提交数据时遇到了action的url跳转问题

  •  
  •   paloalto 2012 年 8 月 4 日 5034 次点击
    这是一个创建于 5011 天前的主题,其中的信息可能已经有所发展或是发生改变。
    站点没有放在根目录,是一个二级目录。

    form页面的地址是类似这样的: http://xxx.com/account/register

    form中的action是这样的 action="/account/register"

    但是这样提交数据之后,就跳到了 http://xxx.com/account/register//account/register 这样的url。

    我想到的一个比较笨的解决办法是把action都写成绝对路径,action="http://xxx.com/account/register" 这样,但是这样的话工作量就比较大了,而且也不灵活。

    不知道大家对这个问题有什么好的解决办法?是不是需要在nginx中改一下配置呢?
    10 条回复    1970-01-01 08:00:00 +08:00
    paloalto
        1
    paloalto  
    OP
       2012 年 8 月 4 日
    这里似乎是个解决办法 http://www.iteye.com/problems/80467
    paloalto
        2
    paloalto  
    OP
       2012 年 8 月 5 日
    唉,他的是针对php的。。
    paloalto
        3
    paloalto  
    OP
       2012 年 8 月 5 日
    把目录转移到了/home/www/下,还是不行,奇怪了。。
    toothpaste
        4
    toothpaste  
       2012 年 8 月 5 日
    这个跟nginx有关还是跟webpy有关?
    我用Apache,我在webpy里写表单,提交给本页的话,会用"./" , 例如"./?register"
    kingwkb
        5
    kingwkb  
       2012 年 8 月 5 日
    这种情况一般都是有可配置的当前域和目录,这样为什么不灵活?换域名改下配置就行了,如果是多域名的话这样也不影响,或许当前域名动态获取,目录配置,改动大吗,不大吧,就是加个配置,action改下就行了
    memorybox
        6
    memorybox  
       2012 年 8 月 5 日
    是用template输出的吗?
    web.py的setting文件里好像要设置一下,我一般是这样:

    templates_root = 'XXX' #模板文件目录
    render = web.template.render(templates_root, cache=False)
    cOnfig= web.storage(
    static = '/static', #这个是静态文件目录
    site_name = 'XXXXX',
    )
    web.template.Template.globals['config'] = config
    web.template.Template.globals['render'] = render

    写路径的时候,基于模板文件的路径来写。如果用到js或css等文件,放到static目录下。
    manhere
        7
    manhere  
       2012 年 8 月 5 日
    action留空就是啊
    ipconfiger
        8
    ipconfiger  
       2012 年 8 月 5 日
    提交到当前地址留空就行了
    paloalto
        9
    paloalto  
    OP
       2012 年 8 月 6 日
    @manhere @ipconfiger 那如果是像这样需要传参数的呢?

    <form method="post" class="default_form reset_password_form" action="/account/reset/$token">
    paloalto
        10
    paloalto  
    OP
       2012 年 8 月 6 日
    @toothpaste

    试了下把 http://xxx.com/account/login页面里的form改成action="./",发现提交后页面跳到了 http://xxx.com/account/

    还试了改成action="./login",结果和action="/account/login"一样,跳到了 http://xxx.com/account/login//account/login

    还有一个问题是:访问 http://xxx.com/account/login 时能正常打开页面,但如果在地址后面加一个“/”, http://xxx.com/account/login/ 页面就会跳转到 http://xxx.com/account/login//account/login

    @memorybox 我觉得不是webpy的问题,也不是static路径的问题。因为我在本地开发时没有这个问题,本地我是用webpy自带的那个服务器,线上是用的nginx。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3015 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 52ms UTC 07:08 PVG 15:08 LAX 00:08 JFK 03:08
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86