开发者

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

开发者 https://www.devze.com 2023-03-04 20:52 出处:网络
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

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.


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

#Alias /test.txt /filesystem/path/to/test.txt


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')


if you are in production, just run

python3 manage.py collectstatics

it will automatically fetch the static file and add it in the desired path.

0

精彩评论

暂无评论...
验证码 换一张
取 消