[英]How to disable cache on Django?
I have a problem with my first django app and I can not find the solution.我的第一个 django 应用程序有问题,我找不到解决方案。 I send this to my controller:我将此发送给我的控制器:
http://localhost:8000/fun1_get_data/?param1_qty=10
The controller:控制器:
@never_cache
def func1_get_data(request):
result = request.GET['param1_qty']
return HttpResponse(json.dumps(result), content_type = "application/json")
Only return the same parameter...very easy...but doesn't work.Only works the first time after restart de server or 'save changes' on archive .py.只返回相同的参数......很容易......但不起作用。仅在重新启动服务器或存档.py上的“保存更改”后第一次有效。
The first time OK:第一次OK:
http://localhost:8000/fun1_get_data/?param1_qty=10
10
And then....进而....
http://localhost:8000/fun1_get_data/?param1_qty=999
10
panic!!恐慌!!
Extra: the template:额外:模板:
url(r'^func1_get_data/', controlador.func1_get_data)
I have a problem with my first django app and I can not find the solution.我的第一个 django 应用程序有问题,我找不到解决方案。 I send this to my controller:我将此发送给我的控制器:
http://localhost:8000/fun1_get_data/?param1_qty=10
The controller:控制器:
@never_cache
def func1_get_data(request):
result = request.GET['param1_qty']
return HttpResponse(json.dumps(result), content_type = "application/json")
Only return the same parameter...very easy...but doesn't work.Only works the first time after restart de server or 'save changes' on archive .py.只返回相同的参数......非常简单......但不起作用。仅在重新启动服务器或存档.py上的“保存更改”后第一次工作。
The first time OK:第一次OK:
http://localhost:8000/fun1_get_data/?param1_qty=10
10
And then....然后....
http://localhost:8000/fun1_get_data/?param1_qty=999
10
panic!!恐慌!!
Extra: the template:额外:模板:
url(r'^func1_get_data/', controlador.func1_get_data)
Go to your Django project and open the urls.py file - Import the cache decorator转到您的 Django 项目并打开 urls.py 文件 - 导入缓存装饰器
from django.views.decorators.cache import never_cache
Use it as function wrapper instead of view decorator将其用作函数包装器而不是视图装饰器
path('', include('home.urls')),
path('', include('blog.urls','blog')),
path('ajax/next-page/', never_cache(views.load_more.as_view()), name='next-page'),
It works for me hope so it also for you.它对我有用,希望对你也有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.