In django routing, I would like to specify a unique function in path(), where I receive a request, add processing, and then invoke class view.
If you access url from the following source, you will get an error.
What I want to do is to do class view.as_view() in the function while receiving a request from another function.
Please help me.
from django.urls import path
from django.contrib.auth.decorators import login_required
from.import views
app_name = 'test'
defaaa(request):
if request.user.i == 0:
return 'url'
else:
return views.TestListView.as_view() ← "This is where the error happen."
urlpatterns = [
path(', aaa, name='test'),
]
Internal Server Error:/alcool/
Traceback (most recent call last):
File"/Library/Frameworks/Python.frameworks/Version/3.8/lib/python 3.8/site-packages/django/core/handlers/exception.py", line 47, inner
response=get_response(request)
File"/Library/Frameworks/Python.frameworks/Version/3.8/lib/python 3.8/site-packages/django/utils/deprecation.py", line 116, in__call__
response=self.process_response(request, response)
File"/Library/Frameworks/Python.framework/Version/3.8/lib/python 3.8/site-packages/django/middleware/clickjacking.py", line 26, in process_response
if response.get('X-Frame-Options') is not None:
AttributeError: 'function' object has no attribute 'get'
The views.TestListView.as_view()
return value is a function.You must call it with a request as an argument.In other words,
return views.TestListView.as_view()(request)
It would be good to say that
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
578 Understanding How to Configure Google API Key
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.