首页 \ 问答 \ webapp2 python正则表达式在路由中(webapp2 python regex in routing)

webapp2 python正则表达式在路由中(webapp2 python regex in routing)

我正在尝试使用webapp2处理表单中的URL:

/case/e3627

其中'e3627'可以是任何字母数字字符串

这是我的路由参数:

app = webapp2.WSGIApplication([(r'/case/<:^\w+$>', ViewCase)],
                              debug=True)

但是我的网址出现了404错误

我也试过<:^[a-zA-Z0-9_]+$>为正则表达式,但没有运气

我的应用程序适用于常规网址,例如/home但不适用于正则表达式

有任何想法吗?


I'm trying to get webapp2 to handle urls in the form:

/case/e3627

where 'e3627' can be any alphanumeric string

Here is my routing arguments:

app = webapp2.WSGIApplication([(r'/case/<:^\w+$>', ViewCase)],
                              debug=True)

But I get a 404 error for my urls

I also tried <:^[a-zA-Z0-9_]+$> for the regex but no luck

My app works fine for regular urls for example /home but not for the regex

Any ideas?


原文:https://stackoverflow.com/questions/15175910
更新时间:2023-07-17 19:07

最满意答案

使用parent.twonav时适合我

DEMO

var links = [
    'javascript:\'<button onclick="parent.twonav(1)">Change 2nd frame</button>\'',
    'javascript:\'Hello\''
];
var one, two;
window.onload=function() {
  one = document.getElementById('frameone');
  two = document.getElementById('frametwo');
}  

function onenav(idx) {
    one.src=links[idx];
}  

function twonav(idx) {
    two.src=links[idx];
}  

Works for me when using parent.twonav

DEMO

var links = [
    'javascript:\'<button onclick="parent.twonav(1)">Change 2nd frame</button>\'',
    'javascript:\'Hello\''
];
var one, two;
window.onload=function() {
  one = document.getElementById('frameone');
  two = document.getElementById('frametwo');
}  

function onenav(idx) {
    one.src=links[idx];
}  

function twonav(idx) {
    two.src=links[idx];
}  

相关问答

更多
  • 是的,绝对可以使用jquery这样做。 我不确切知道iframe中的代码是什么样的,但是要按名称选择iframe,例如,你会这样做: $("iframe[name='figher_profile']").contents(); 然后设置它的高度 $("iframe[name='figher_profile']").height($("iframe[name='figher_profile']").contents().find("html").css("height", "100")); //Settin ...
  • 您可以将src属性设置为Web服务器上的一个页面,该页面将html作为纯文本输出,而不是HTML格式。 因此,您必须将标题信息内容类型设置为text / plain。 查看此页面,了解它是如何在PHP中完成的: http : //www.jonasjohn.de/snippets/php/headers.htm 没有办法只用html或js来做到这一点。 你需要一些服务器端语言来渲染页面。 当然,可以通过xmlhttprequest从js中的web服务器中检索数据,这个更好的称为AJAX。 You can s ...
  • 您在创建要尝试修改的元素的HTML之前有Javascript,因此getElementById()没有找到该元素。 将添加JS的PHP代码移动到HTML的末尾,以便找到ID。 或者将Javascript放在窗口的load处理程序中。 "; echo "window.addEventListener('load', function() {"; echo "d ...
  • 在触发任何特定event后,您必须更改src 。 所以试试这种方式, HTML: javaScript: var iframe = document.getElementById("m ...
  • 数据URI方案适用于直接嵌入数据。 data:text/html;base64,aHR0cDovL2V4YW1wbGUuY29t 表示以"http://example.com"为唯一内容的html页面。 你可能想要"http://example.com"作为src The Data URI scheme is for direct embedded data. data:text/html;base64,aHR0cDovL2V4YW1wbGUuY29t Means a html page with "h ...
  • 请查看Google Web Designer帮助> iFrame组件 。 Please take a look into Google Web Designer Help > The iFrame component.
  • 对于iframe中的任何锚标记,请尝试将目标设置为_self。 喜欢这个: Test 我会玩它,但我知道这是旧学校框架的标准。 编辑基于我所做的一些测试,iframe中锚链接的默认操作是在iframe中加载新内容。 target =“_ self”是多余的,除非有其他东西覆盖它。 也许您应该提供有关源代码的更多信息,如果这不是为您解决的话。 我也可以假设您使用javascript遇到了问题。 ...
  • 使用parent.twonav时适合我 DEMO var links = [ 'javascript:\'\'', 'javascript:\'Hello\'' ]; var one, two; window.onload=function() { one = document.getElementById('frameone'); two = document.g ...
  • 示例:main.php