开发者

How can I match the url in html

开发者 https://www.devze.com 2023-02-15 04:27 出处:网络
<form action=\'/[0-9]+\' method=\"POST\"> <input type=\"submit\" value=\"delete question\" name=\"delete\">
<form action='/[0-9]+' method="POST">
    <input type="submit" value="delete question" name="delete">
</form>

what above is the html template I am using for the appengine project. Besides that, i created a web request handler class to handle this request. ('/[0-9]+',QuestionViewer), it is supposed to catch any url in digits. However, turns on that after I clic开发者_如何学JAVAk on the delete button above, my page is directed to some url like main/[0-9], I dont know if I can use regex in the django template, or is there a away that my QuestionViewers class can catch the url in digits? since my url associated with the html page is dynamic, like the parts after / ,like /13,are changing accordingly and I cant do that only works for page 13 but not for /14 or something like these. Hope I make it clear. any helps? Thank you a lot.


That doesn't really make sense. You want to submit your form to a regex rule? What would it match against?

No, the form needs to submit to a specific url. Right now, it's trying to submit to /[0-9]+

If I understand what you are saying, and you want to submit from a url such as /13/ to your QuestionViewer at /[0-9]+, simply submit without the action attribute or set it to "" to post to the current url.

Note that if you want to use the digit captured in your regex, you need to surround your regex in parenthesis such as '/([0-9]+)/$', QuestionViewer or use a named regexp /(?P<id>[0-9]+)/$ to pass in an argument of id equal to the matched regex to QuestionViewer.

http://docs.djangoproject.com/en/1.0/topics/http/urls/#how-django-processes-a-request


The value of the action attribute must be a valid URL.

I think what you want is to generate an actual number for the action url; a number that is the number of the question that you want to delete. For example:

<form action="/1234" method="POST">

You will need to change your code to make sure you do this.

0

精彩评论

暂无评论...
验证码 换一张
取 消