简体   繁体   中英

How to include HTML file uploaded by user - Django

I'm including ads in my project's html files i was using GIF files Upload it in the admin and use it like :

{{ ad.image.url }}

but then the client wanted the ad to be HTML file (with js, CSS files) i thought of:

  • Upload a zip file containing all files and extract it to media directory but don't know the best way to achieve this
  • upload each file individually and link it to the ad ID but the problem is what if there were directories not just files?

and the main problem is how to inject/include the HTML file content to my HTML page?

Please share your ideas

you can create an upload page for image / css and js files.

and a single html file stored into models or file.

in your view you can load content of html file then pass it to template then render content of passed parameter

{{ file_content|safe }}

also you can use iframe to show page content

also to create html file you can use one WYSIWYG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM