This is really a newbie question, but I don't know how to search answers for this. I want to use pystache, and I am able to execute the .py file to print out some rendered output from .mustache file. but how exactly do I convert this into .html file? Specifically, how to put it on the server so that the browser would direct to the .html file like index.html?
Pystache is a template library not http server! If you want make webapp try to use ready-made webframeworks like Django or Pyramid.
Related
I have a question for you!
I'm running a simple webserver with twistd web and it works great must of the time. I have a problem serving .docx files.
Let me explain with an example.
On my webserver I have two files: file.pdf and file.docx (the x is important).
Now, on my browser, if I enter the URL of the pdf file, the browser will start the download (or open it depending on user preferences). This is the expected behavior.
But if I enter a link to a docx, instead of downloading it, the browser will display it as a sequence of strange letters and numbers.
It is not a browser issue, because if a click on a docx file served from another webserver, the browser will download it.
I'm starting the webserver directly from the windows cmd prompt using twistd. The line looks like this:
twistd -no web --path d:\shares\
The question is: how can I tell twistd to force the download of docx file the same way it does for pdf?
Thanks
It might help if you shared some of your code, but I think the basic idea is that you should add the correct MIME type to the header that your server returns, which will help the browser know what to do with it rather than try to render it as text. Based on the docs here it looks like you want something like this:
from twisted.web import static
root = static.File("/files")
root.contentTypes[".docx"] = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
Using the somewhat long-winded MIME type for docx.
I'm working on a demo for a program that creates some files on its own directory. This demo will be shown to someone physically far, via VPN, so I made a simple django project just to receive an input, call some scripts and display the output - the generated file. However, I don't have permission to open the file to display it since it's on a directory outside of the django project (the result is a permission denied error).
I'm aware it's not good practice or even safe for a web server to have access to files outside of its directories, but since this will run in a closed environment for a short amount of time only, is there a workaround?
Think of it this way - If web server can generate the files , it can display them also.
As for your answer - if you know the path of the file, use the python open built in method to open the file and render the result to a template.
data = open('file_path').read().decode('utf-8')
render(request, template, context={data:data})
I have 10 line python code and a third party python library that I want to use in a html website. I do not want to use a full fledged framework like django to complete the task. I want to use the following library https://github.com/nficano/pytube in my project. Thank You looking forward for some assistance.
The most simple thing come to my mind is following.
1) You'll need to use some sort of WSGI (https://uwsgi-docs.readthedocs.io/en/latest/, for example), to serve your script as a web service.
2) You'll also need a little bit of JavaScript code to make AJAX (for example) requests to that script.
Can I use CGI module to read and extract information from an uploaded FormData object file in python?
The file is being uploaded on the server from the front end and I'd like to read the file and extract data from it.
So how do I go about it?
Try this minimal recipe using web.py. Remove debug output, write to a file, otherwise update to taste. E.g. you might want authentication at this endpoint.
It's a pip install web.py away.
Is it possible to create html files using either CloudStore or Blobstore?
I want to create a function that will make post calls with html content to my GAE server, the Server will create an html file with this content and will send back the url of this new file. I think it's pretty simple but I don't find the way to do that using Google App Engine.
I would highly appreciate any help on this!
Thanks a lot!
You can post (upload) all kinds of files, like html files and receive a serving url.
See this GIST