1π
β
To make this work, you need to allow the external web service to make cross-origin request. The easiest way to do it is by installing django-cors-headers package and add your service hostname in the settings.py
like so:
CORS_ORIGIN_WHITELIST = (
'myservice.com',
)
where myservice.com
is the external service that makes the ajax call. Also remember to follow these setup instructions.
π€mariodev
0π
For Django Framework itself, you can do the following:
Instead of URL βhttps://origin.comβ you can place a wildcard β*β or any other URL.
class PriceListTableView(TemplateView):
template_name = "pages/price_list_table.html"
def get(self, request, *args, **kwargs):
response = super().get(request, *args, **kwargs)
response['Access-Control-Allow-Origin'] = 'https://origin.com'
return response
Might or might not apply to Django REST Framework.
π€Maziyar Mk
- [Answer]-How to call method save() in a Django model class using attr string name?
- [Answer]-Django framework can't see new model online
- [Answer]-Serving static HTML files without extension in Django
Source:stackexchange.com