Django: locals () Tips

Source: Internet
Author: User
Locals () returns a dictionary containing all the variables and their values in the current scope. Therefore, you can rewrite views to defcurrent_datetime (request): current_datetime.datetime.now()returnrender_to_response(current_datetime.html, locals (). Note that now must be duplicated.

Locals () returns a dictionary containing all the variables and their values in the current scope. Therefore, you can rewrite views to def current_datetime (request): current_date = datetime. datetime. now () return render_to_response('current_datetime.html ', locals (). Note that you need to replace now

Locals () returns a dictionary containing all the variables and their values in the current scope.

So you can rewrite views

Def current_datetime (request): current_date = datetime. datetime. now () return render_to_response('current_datetime.html ', locals ())

Here, you need to rename now to current_date, because the template requires the variable name.

The template is defined as follows:

It is now {current_date }}.

Previously, because now is still used, the result is that the access time is http: // localhost: 8000/time/

Is displayed as blank.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.