hai i am newbie in django and sorry for grammar mistake
first i have some project to upload file extension .html
to AWS S3, so in views.py
i want to render a link i've already uploaded to AWS S3. ex: render(request, 'somelink.com', context)
, it possible? or any other solution? and also i want to send context parameters
why i not using media_url upload to local? cause i have limited disk, and other problem when i do production i cant load media_url, ignore this case, cause i already try many solution
CodePudding user response:
Assuming that you want to render it server side, you will need to fetch the template (the .html
file) and render it.
You can do it using the requests
library to fetch the url template. And the Django template render engine to render the context: https://docs.djangoproject.com/en/4.1/ref/templates/api/#rendering-a-context
import requests
from django.template import Template, Context
template = requests.get('somelink.com').content
t = Template(template)
c = Context(context)
return HttpResponse(t.render(c))
Notes:
- It can worse the response time from your server.
- As you are concerned about space, you can try to use a front-end solution to render data from your server via API.
Hope it can help you.