Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - Return a file from Root folder via a URL

I purchased a SSL cert online and now ind the mid of verifying my host. How it works is:

  1. It gives me a file
  2. I have to make that file accessible through a specific URL on my host.
  3. If the content of the file matches, it's verified.

Now I'm at step 2.

I'm trying to return a file (static) from an URL, as required by Comodo to verify my server. So basically, I think if I access this link:

http://your(sub)domain/.well-known/pki-validation/<filename.txt>

The guide is here:

https://helpdesk.ssls.com/hc/en-us/articles/206957109-How-can-I-complete-the-domain-control-validation-DCV-for-my-SSL-certificate-

Can you guys help how I can return a file with this URL? Thanks!

like image 726
knl Avatar asked Dec 23 '22 00:12

knl


1 Answers

Thanks for all your help. I actually found out that it was pretty straight forward.

I just put a path in my urls.py as below:

urlpatterns = [
      path('.well-known/pki-validation/xxxyyyzzz.txt', read_file),
            ]

Then my read_file function just simply return the file with

def read_file(request):
    f = open('.well-known/pki-validation/xxxyyyzzz.txt', 'r')
    file_content = f.read()
    f.close()
    return HttpResponse(file_content, content_type="text/plain")
like image 199
knl Avatar answered Jan 02 '23 15:01

knl