mrmo123
mrmo123

Reputation: 725

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.

Upvotes: 3

Views: 179

Answers (1)

Insidi0us
Insidi0us

Reputation: 1126

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

Upvotes: 2

Related Questions