Django - Return a file from Root folder via a URL

2024/10/3 17:09:19

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!

Answer

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")
https://en.xdnf.cn/q/70709.html

Related Q&A

Flask deployement on lighttpd and raspberry pi

Im trying to deploy a hello flask app to a raspberry pi using lighttpd fastCGI.I followed the instructions on the http://flask.pocoo.org/docs/0.10/deploying/fastcgi/ to the best of my abilityHere is my…

Django admin asks for login after every click

Im working on a Django app hosted on Heroku. Im able to login to the admin with my username, password. But on every single click (or on each click after a few seconds) it redirects me to the login page…

Change numerical Data to Categorical Data - Pandas [duplicate]

This question already has answers here:How to create new values in a pandas dataframe column based on values from another column(2 answers)Closed 6 years ago.I have a pandas dataframe which has a numer…

Why is dataclasses.astuple returning a deepcopy of class attributes?

In the code below the astuple function is carrying out a deep copy of a class attribute of the dataclass. Why is it not producing the same result as the function my_tuple? import copy import dataclass…

customize dateutil.parser century inference logic

I am working on old text files with 2-digit years where the default century logic in dateutil.parser doesnt seem to work well. For example, the attack on Pearl Harbor was not on dparser.parse("12…

How can I check a Python unicode string to see that it *actually* is proper Unicode?

So I have this page:http://hub.iis.sinica.edu.tw/cytoHubba/Apparently its all kinds of messed up, as it gets decoded properly but when I try to save it in postgres I get:DatabaseError: invalid byte seq…

Test assertions for tuples with floats

I have a function that returns a tuple that, among others, contains a float value. Usually I use assertAlmostEquals to compare those, but this does not work with tuples. Also, the tuple contains other …

Django: Assigning ForeignKey - Unable to get repr for class

I ask this question here because, in my searches, this error has been generally related to queries rather than ForeignKey assignment.The error I am getting occurs in a method of a model. Here is the co…

Counting day-of-week-hour pairs between two dates

Consider the following list of day-of-week-hour pairs in 24H format:{Mon: [9,23],Thu: [12, 13, 14],Tue: [11, 12, 14],Wed: [11, 12, 13, 14]Fri: [13],Sat: [],Sun: [], }and two time points, e.g.:Start:dat…

Download A Single File Using Multiple Threads

Im trying to create a Download Manager for Linux that lets me download one single file using multiple threads. This is what Im trying to do : Divide the file to be downloaded into different parts by sp…