Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add resources to url in python google app engine

I'm trying to make a blog/news site and would like to have articles have the url: http://mysite.com/2012/02/05/slug/
My problem is appending the /2012/02/05/slug/ to the url in python. I can save the date and slug into Gql database, as well as the article's content. I just don't how to add the date and slug resource into the url. Searching google hasn't really worked because I don't know what this technique is called...but know most new/blog sites implement it. Appreciate any help. Thanks in advance.

like image 636
mrmo123 Avatar asked Mar 24 '26 08:03

mrmo123


1 Answers

If you are looking for a general function

import urlparse

def url_rev(pubdate, slug):
    return urlparse.urljoin('http://mysite.com',
                            '/%s/%s/%s/%s/'%(pubdate.year, pubdate.month, pubdate.day, slug))

But
If you are using webapp2: uri_for
if you're using App Engine Patch, you can use Django, including its URL resolvers.
If you are using Flask you can use url_for

like image 88
Insidi0us Avatar answered Mar 25 '26 20:03

Insidi0us



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!