#Issue when using copy of base.html from rest_framework
1 messages · Page 1 of 1 (latest)
I'm thinking that my template is not able to load the templatetags file form Django REST framework.
But here is my app/middle were everything looking right fot me :
Django Version: 5.0.3
Python Version: 3.11.8
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'daphne',
'django.contrib.staticfiles',
'corsheaders',
'rest_framework',
'django_eventstream',
'django_celery_results',
'django_celery_beat',
'puml_generator',
'drf_spectacular',
'drf_spectacular_sidecar',
'app']
Installed Middleware:
['corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_grip.GripMiddleware']
I have tried to find some info about that but nothing.
Do i need to reproduce the templatetags in my own app ?
Thanks for help !
The my new base.html i'm using is the same that you can find here :
https://github.com/encode/django-rest-framework/blob/master/rest_framework/templates/rest_framework/base.html
please
Why exactly are you extending DRF's base.html ?
And the reason you're getting that error is because this template expects csrf_token in the context.
Yes but why it didn't directly as it ?
because I need to edit the response filed.
I'm working on an upgrade of this plugin :
https://github.com/fanout/django-eventstream
By addind support for views, and borwsable api for support for rest-framework
I would like to replace the response field to display the SSE stream.
But that not possible by default
How can I be sure that csrf_token is send to the templatags ?
Well, this template is intended to be served by the corresponding view. DRF views are feeding the context to the template. Even if you resolve the csrf_token you will land on other errors.
I can't be of more help on this subject as I haven't overriden DRF's templates before.
Mmm ok, i will try something and come back.