上次我写的答案是快速有效的,所以我再来一次。
我有这三个文件,2 .py和一个html。问题是,由于某种原因,我得到了错误404.显然我的网址是处理这个问题的。这是我的代码
# encoding: utf-8
import web
import os
import gettext
import signup
import verify_email
urls = (
"/", 'Index',
"/sign-up", signup.app_signup,
"/verify_email", verify_email.app_verify_email
)
# Internacionalización:
current_directory = os.path.abspath(os.path.dirname(__file__))
locales_directory = current_directory + '/i18n'
gettext.install('messages', locales_directory, unicode = True)
gettext.translation('messages', locales_directory, languages = ['es']).install(True)
web.config.debug = False
app = web.application(urls, locals())
session = web.session.Session(app, web.session.DiskStore('sessions'))
db = web.database(dbn='postgres', user='zoosalud', pw='pbF8zCxd4gZUmhRxd8AsjfhN', db='zoosalud')
def session_hook():
web.ctx.session = session
web.ctx.db = db
web.ctx.render = render
app.add_processor(web.loadhook(session_hook))
render = web.template.render('views/', globals = {'session': session, 'db': db, '_': _})
class Index:
def GET(self):
user_input = web.input()
user_input.names = ''
user_input.surnames = ''
user_input.nin = ''
user_input.address = ''
user_input.municipality = 0
user_input.phone = ''
user_input.email = ''
session.user_input = user_input
session.errors = []
return render.access()
if __name__ == "__main__":
app.run()
这是我的子应用
# encoding: utf-8
import bcrypt
import email_setup
import uuid
import web
urls = (
"/", "SignUp"
)
class SignUp:
def POST(self):
user_input = web.input()
web.ctx.session.errors = []
user = web.ctx.db.select('role', where="email='" + user_input.email + "'")
if user:
web.ctx.session.errors.append('email_taken')
user = web.ctx.db.select('role', where="nin='" + user_input.nin + "'")
if user:
web.ctx.session.errors.append('nin_taken')
if user_input.password != user_input.confirm_password:
web.ctx.session.errors.append('passwords_not_match')
if user_input.municipality == '0':
web.ctx.session.errors.append('unselected_municipality')
if web.ctx.session.errors:
web.ctx.session.user_input = user_input
return web.ctx.render.access()
app_signup = web.application(urls, locals())
和我的HTML
<form method=post action="sign-up">
<ul>
<li><input name=names required maxlength=24 placeholder=$_('name') value="$session.user_input.names"></li>
<li><input name=surnames required maxlength=24 placeholder=$_('surname') value="$session.user_input.surnames"></li>
<li><input name=nin requiered maxlength=12 placeholder=$_('nin') value="$session.user_input.nin"></li>
<li><input name=address required maxlenght=64 placeholder=$_('address') value="$session.user_input.address"></li>
<li><select id=municipality name=municipality>
<option value=0>$_('municipality'):</option>
$for municipality in municipalities:
<option value=$municipality.id>$municipality.name</option>
</select></li>
<li><input name=phone required maxlength=10 placeholder=$_('phone') value=$session.user_input.phone></li>
<li><input name=email type=email required maxlenght=254 placeholder=$_('email') value=$session.user_input.email></li>
<li><input name=password type=password required placeholder=$_('password')></li>
<li><input name=confirm_password type=password required placeholder=$_('confirm_password')></li>
<li><input type=submit value="$_('sign_up')"></li>
</ul>
我提到的问题是当我在子应用程序中映射到“/”时的错误404,这很奇怪,因为当我映射到“”它确实有效,但现在我需要映射它以便我可以获得路径GET,这个解决方案长期不起作用。
先谢谢你们。
答案 0 :(得分:1)
您可以将子应用程序映射更改为"/?", "SignUp"
,以便它可以使用和不使用尾部斜杠。