I created a Django project which I use in Apache server.
The project simply edits an .m3u file when you press a button on a page, and generates a new .m3u file. The script works as intended.
Can Django generate a download link automatically for this newly generated .m3u file? I understand from many tutorials that I need to edit the urls.py and view.py files, but I need it to be done automatically.
Or another option would be to make the file downloadable via Apache directly if something like this is possible.
is that is it possible Django can generate a download link automatically for this newly generated m3u file
Yes. I assume this is a static file located somewhere on the server. You can make file generator script/function return the location of generated file on server. The download URL can take location of this fileas a query parameter. You can make this file available using Django.
Or another option would be to make the file downloadable via apache diretly if something like this is possible.
Yes, you can. See Can you make a file downloadable through Apache?
Related
I am new to SharePoint. I have written a simple python script that basically connects to SharePoint and uploads files (aspx and other frontend files) from a folder on my local machine to a specific folder on SharePoint site.
To facilitate the script to communicate with the SharePoint, I have a created an App principal under SharePoint using the SharePoint App-Only model. I have done this by calling the appregnew.aspx, example: https://spo.test.com/sites/MYSITE/\_layouts/15/appregnew.aspx , below is the sample page when 'appregnew.aspx' is called
Then, I have provided the below permissions to the App principal through 'appinv.aspx', example - https://spo.test.com/sites/MYSITE/\_layouts/15/appinv.aspx
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl"/>
</AppPermissionRequests>
Next, I use the Client ID and Client Secret under the Python script to establish communication with SharePoint and to upload files to a specific folder (folder already exists and is not created by the program) on SharePoint, example path to which files are uploaded: https://spo.test.com/sites/MYSITE/Shared%20Documents/TeamDocs2
Note: This script uses Python library 'Office365-REST-Python-Client' to communicate with SharePoint
The script can successfully authenticate itself and also upload the files to the folder on SharePoint. But then when I manually go to the SharePoint folder and click on the aspx file, example : index.aspx; the file gets downloaded instead of getting rendered.
There is no issue with the file i.e. it is not corrupted because when I manually upload the same file onto the same folder, then there is no issue, the file gets rendered.
In regards to the permissions for the App principal, I've already given 'FullControl' at the scope 'sitecolletion/web' level. I also tried changing the scope from 'http://sharepoint/content/sitecollection/web' to 'http://sharepoint/content/sitecollection', this didn't work as well
Please can somebody help me with this. Thanks in advance
The reason the .aspx page is being downloaded is related to security risk mitigation in SharePoint. If you consider that Javascript (.js) files and .aspx files are executable files in the browser, then it should also be self evident that allowing users to upload such files to SharePoint could pose risk. Because of this, Microsoft has disabled custom script on all modern sites by default. You can choose to overrule this setting, but it should be done with extreme caution.
I'm trying to download a file from a local directory in a Django template, but when I click and download it, I get a File Not Found error on my browser. As soon as I click download, the file explorer to choose the folder opens, but when I save the file I get that error. The path to the file I'm sure is right.
index.html
Download
Django doesn't serve static files by itself.
In order to create a file download link, you need to have a Django view that serves the static file. Refer here for more details https://djangoadventures.com/how-to-create-file-download-links-in-django/
I have a working Python script that generates and saves hi-res image files to a local Dropbox folder (synced through the Windows Dropbox app). Is there a way in Python to change the SmartSync setting for the newly created image from "Local" to "Online Only" so that I can save space on my local hard drive? I know I could use the Dropbox API v2 to just upload the file and then delete the temporary local files after, but I'm wondering if there is a way to directly change the file settings since it already gets saved to the synced Dropbox folder.
Thanks!
No, unfortunately Dropbox doesn't offer an API for managing Smart Sync settings like this, but I'll pass this along as a feature request.
I am working on a cookiecutter-django project that requires users to be able to upload files in the .5-1gb size range. From what I understand when uploading files that are larger then 2.5Mbs django uses the TemporaryFileUploadHandler to first upload the file to the tmp directory and then to then transfer them to the media directory. However when I try to upload a larger file my site just hangs, I don't see any files come into the tmp directory, and I see no errors in the logs.
Is there some setting I need to turn on to instruct django to use the TemporaryFileUploadHandler? Or is there some way to possibly figure out where the site might be getting hung up? I am currently building out this project locally so I have full control over my environment.
I am using Python 3.4.5 and django 1.10
UPDATE 1
I have tested uploading files of 5mb, 10mb, 20mb, and 30mb they all upload fine. The file I am having issues with is 873mb.
UPDATE 2
After more debugging I have found that when up loading a large file to my site it gets as far as the get_form method on my view class. After that I am not sure what is called. I have been slowly adding logs at each step in the hopes of figuring out where it is stuck.
I've written a scientific program in python which outputs a .png and a .pdf
I would like to execute this main.py file from a web interface, with a nice big button saying GO and then display the .png and download a .pdf
I'm using a Django framework to serve the page saying GO. How do i get it to:
run my main.py file?
return the .png file to html template?
download the file which is generated by the main.py script?
Thank you internet
This question is a little broad for a specific answer, but in general, one can:
Have the button access an API which will, on the server, in another thread, your main.py file.
Once the application is finished, move the generated files to a deterministic location that serves static files on your web server.
Provide the user a URL to the newly created file's location.
Have a cron job run to clear out old files in the static directory.