Since it's a static media file, the usual Django recommendation is to
not use Django at all.  I would suggest adding an entry for it in your
web server software to serve the media directly instead of using a
Django handler.

Also, if you're really set on using Django to serve this, you'll
probably want to use the template loading system or
render_to_response.  Notice that open() will never throw
TemplateDoesNotExist.  It also won't look in the templates directory,
but rather it will look in the directory specified by os.getcwd().

Hopefully this helps,
Eric Florenzano

On Feb 14, 1:53 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> I built a Django site for my blog and want to serve a robots.txt file
> for it. But I can't figure out how to go about doing this since it's a
> static file.
>
> Here is what I have in my urls:
>
> from patrickbeeson.views import robots
> ...
> (r'^robots.txt$', robots),
>
> From the views:
>
> from django.http import HttpResponse
> from django.template import TemplateDoesNotExist
>
> def robots(request):
>         try:
>                 return HttpResponse(open('robots.txt').read(), 'text/plain')
>         except TemplateDoesNotExist:
>                 raise Http404()
>
> The "robots.txt" file is located in my templates directory with other
> templates.
>
> Any suggestions on what I might be doing wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to