Forums

Static robots.txt file

Ok. I'm new, so sorry if this is simple but I've looked throughout the forums and read everything I can on static files and still can't get this to work.

I want www.planetquilt.com/robots.txt to serve the static robots.txt file in the /static/ folder and I simply can't get it done.

www.planetquilt.com/static/robots.txt works fine so I know it is accessible.

I've been trying all manners of url patterns in the urls.py

url(r'^robots\.txt$', TemplateView.as_view(template_name="static/robots.txt", content_type='text/plain')),

I've tried /robots.txt /static/robots.txt static/robots ect ect

My static_root and static folder all seem to work fine, I can browser out to images and css and ect ect that is hosted in the static folder, and the robots.txt clearly lives there since I can hit it via /static/robots.txt but no matter what I do I can't seem to get the url to recolonize / server it at the base level

laughs in Flask

Hey Dull, Crazy helpful post, A+ would read again. Solid community input.

I'm new to python / django and picked pythonanywhere specifically cause I thought it was supposed to be a community willing to help new people, if I'm wrong let me know, I can spend my money elsewhere.

I would help you if I knew how to use Django

The staff should be able to help with Django, and they have been helpful for me

But they usually don't respond as fast as I do

I'm new to python / django and picked pythonanywhere specifically cause I thought it was supposed to be a community willing to help new people, if I'm wrong let me know, I can spend my money elsewhere.

People are generally very helpful here

We do try to build a good community here!

Check out this. For both Django and Flask, if you have static files, it would be more efficient to serve them directly using the files to urls static mapping that you can config from your Web tab. Then we do that for you, and your django code itself wouldn't need to deal with serving static files, and frees it up to process other incoming requests.

Hello,

I have added the following in urls.py and it seems to work:

from django.views.generic.base import RedirectView from django.urls import re_path

....

urlpatterns += [re_path('^robots.txt$', RedirectView.as_view(url='/static/robots.txt', permanent=False), name='robots')]

Looks like it's one of the ways to do it.

......or, simply map /robots.txt to /static/some/where/down/a/tree/robots.txt in your web apps "Static Files" section.

That may also work.