开发者

add extra data to response object to render in template

İ ned to write a code sniplet that enables to disable connection to some parts of a site. Admin and the mainpage will be displayable, but user section (which uses ajax) will be displayed, but can not be used (vith a transparent div set over the page). Also there is a few pages which will be disabled.

my logic is that, i write a middleware,

def process_request(self, request):
    if ayar.tonline_kapali:
        url_parcalari = request.path.split('/')
        if url_parcalari[0] not in settings.BAGIMSIZ_URLLER:
            if not request.is_ajax():
                return render_to_response('bakim_modu.html')
    else:
        return None

that code let me to display a "site closed" message for the urls not in BAGIMSIZ_URLLER (which contains urls that will be accessible)

But i do not figure out how can i solve the problem about ajax pages... i need t开发者_开发技巧o set a header or something to the response and need to check it in the template.


here documentation for process_view Usage is simple. process_view is called just before Django calls the view, and get few arguments: request - Request object view_func - View function view_args - Arguments view_kwargs - Keyword arguments

Which example do you need?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜