Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django: how to put a static file under root directory?

Tags:

django

I am connecting to a SNS website and the website requires me to put a file at the root directory of the domain, such as http://www.a.com/test.txt and it will fetch it automatically to verify I am the owner of the domain.

I am using django and all the static files are under http://www.a.com/static/, how can I write the URL file to specify a file test.txt so that when the robot of the SNS website fetch the URL http://www.a.com/test.txt, it will correctly fetch the file I uploaded?

Thanks.

like image 885
Bin Chen Avatar asked May 08 '11 13:05

Bin Chen


2 Answers

If you are running apache, set up an alias in apache's httpd.conf:

#Alias /test.txt /filesystem/path/to/test.txt
like image 166
Mihai Oprea Avatar answered Nov 15 '22 04:11

Mihai Oprea


There's no reason why it has to be an actual physical file. You could just as easily return whatever magic text is required via a view, mapped to the relevant URL:

url(r'^test\.txt', 'test_view')


def test_view(request):
    return HttpResponse("My magic text here", mimetype='text/plain')
like image 24
Daniel Roseman Avatar answered Nov 15 '22 04:11

Daniel Roseman