You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple URL rewriting mechanism would be very very welcomed. The good news is it's perfectly safe to add URL rewriting to Drapache and I will surely enable certain kinds of apps and scripts to be much more easily written this way.
Something with all of the power of mod_rewrite in Apache would be cool but I guess we don't need it since we got Python, right?
How about redirecting all 404s to a top level _rewrite.dbpy script if it's present?
Once you have that you would only need to provide us with a way to read the original requested path and we can put together our own pattern matching and URL rewriting mechanism.
Here's some code sample to help illustrate the idea:
import re
request = dbpy.http.get_request()
m = re.compile('^/posts/(?P<post_id>\d+)$')
if m.matches(request.redirect_uri):
post_id = m.groupdict()['post_id']
dbpy.http.redirect('/read_post.dbpy?post_id=%d' % post_id)
The text was updated successfully, but these errors were encountered:
hey @gnrfan, this is a good idea. i definitely agree that routing is something that its missing, and I was working on a possible implementation when I released it.
my idea was to have one dbpy file, and then the requested path as a query parameter,
So that one file will get executed every time, and it knows what route the user is trying to get.
the idea of the 404 exception handler is a really cool one though, the downside is an unnecessary request to dropbox.
it would have to be implemented at a high level in the request, probably in dbserver.py. There is a catch block there that catches a dropbox ErrorResponse. That's where 404s originate, so that's where they could be caught.
Sounds good. How about having both mechanisms and making the completely optional? I'd say they could be placed in the top level of the folder and be called _router.dbpy and _notfound.dbpy respectively.
Something to work out with both would be a way to directly dispatch the re-routed request from the server side without sending a redirection response to the client.
A simple URL rewriting mechanism would be very very welcomed. The good news is it's perfectly safe to add URL rewriting to Drapache and I will surely enable certain kinds of apps and scripts to be much more easily written this way.
Something with all of the power of mod_rewrite in Apache would be cool but I guess we don't need it since we got Python, right?
How about redirecting all 404s to a top level _rewrite.dbpy script if it's present?
Once you have that you would only need to provide us with a way to read the original requested path and we can put together our own pattern matching and URL rewriting mechanism.
Here's some code sample to help illustrate the idea:
import re
request = dbpy.http.get_request()
m = re.compile('^/posts/(?P<post_id>\d+)$')
if m.matches(request.redirect_uri):
post_id = m.groupdict()['post_id']
dbpy.http.redirect('/read_post.dbpy?post_id=%d' % post_id)
The text was updated successfully, but these errors were encountered: