Custom url in django Django sitemap

664 views
Skip to first unread message

eli

unread,
Sep 9, 2009, 11:41:57 AM9/9/09
to Django users
Hi,

How to add custom static url (they are not in database) to Django
Sitemap? for ex: /about-me.html, /contact.html, /some-static-url.html

regards.

Peter Coles

unread,
Sep 9, 2009, 12:47:21 PM9/9/09
to Django users
Hi eli,

If you want serve a "static file" (that never changes and doesn't take
advantage of django's template system) then you shouldn't be serving
it with django. You can use django if you really want:
http://docs.djangoproject.com/en/dev/howto/static-files/ but you're
better off having your server (like apache) handle it directly:
http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id1

However, you may want your about-me page to inherit a header and
footer or other stuff from a base template (if you don't know what I'm
talking about read this: http://docs.djangoproject.com/en/dev/intro/overview/#intro-overview
) -- if that's the case, you can use the direct_to_template generic
view as described here:

http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-simple-direct-to-template

-Peter

eli

unread,
Sep 9, 2009, 6:11:07 PM9/9/09
to Django users
Hi,

Thanks for replay, but I was talking about the django sitemap
framework http://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/ ,
and problem: how to add my custom page (serving by server) to output
(XML) of the django sitemap framework?

regards.

On 9 Wrz, 18:47, Peter Coles <pe...@hunch.com> wrote:
> Hi eli,
>
> If you want serve a "static file" (that never changes and doesn't take
> advantage of django's template system) then you shouldn't be serving
> it with django.  You can use django if you really want:http://docs.djangoproject.com/en/dev/howto/static-files/but you're
> better off having your server (like apache) handle it directly:http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id1
>
> However, you may want your about-me page to inherit a header and
> footer or other stuff from a base template (if you don't know what I'm
> talking about read this:http://docs.djangoproject.com/en/dev/intro/overview/#intro-overview
> ) -- if that's the case, you can use the direct_to_template generic
> view as described here:
>
> http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-...

Peter Coles

unread,
Sep 11, 2009, 6:18:17 PM9/11/09
to Django users
Ah, sorry :)

You just have to write a custom Sitemap class. The docs say that it
doesn't matter what type of objects are returned by items as long as
your sitemap class knows how to get the necessary information from
them.

Read the docs here: http://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/#a-simple-example

And them code up something like this:

class StaticPagesSitemap(Sitemap):
changefreq = "never"
priority = 0.5
def items(self): return ['/about_me.html', '/contact.html', '/some-
static-url.html']
def location(self, obj): return obj

and add it to your sitemaps dictionary that gets passed into your
sitemap.xml in your urls.py file:

sitemaps = {
...
'staticpages': StaticPagesSitemap,
}

Enjoy!

--
Peter

On Sep 9, 6:11 pm, eli <eliasz.wont...@gmail.com> wrote:
> Hi,
>
> Thanks for replay, but I was talking about the django sitemap
> frameworkhttp://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/,
> and problem: how to add my custom page (serving by server) to output
> (XML) of the django sitemap framework?
>
> regards.
>
> On 9 Wrz, 18:47, Peter Coles <pe...@hunch.com> wrote:
>
> > Hi eli,
>
> > If you want serve a "static file" (that never changes and doesn't take
> > advantage of django's template system) then you shouldn't be serving
> > it with django.  You can use django if you really want:http://docs.djangoproject.com/en/dev/howto/static-files/butyou're
Reply all
Reply to author
Forward
0 new messages