Django project 2

Source: Internet
Author: User

1. preparation [plain] django-admin.py startproject web01 django-admin.py startapp tim python manage. py runserver 2. settings register [python] INSTALLED_APPS = ('django. contrib. auth ', 'django. contrib. contenttypes ', 'django. contrib. sessions ', 'django. contrib. sites ', 'django. contrib. messages ', 'django. contrib. staticfiles ', 'Tim',) 3. configure url [python] from django. conf. urls. defaults import patterns, include, url urlpatterns = patterns ('', url (R' ^ tim/current/$ ', 'Tim. views. current '), # map views. current url (R' ^ tim/plus/(\ d {1, 2})/$ ', 'Tim. views. ahead'), # convert the numeric part to a tuples to be conveniently set to offset.) 4. views file. You do not need to import external html files here, so you do not need loader or Context. [python] # coding: utf8 from django. http import HttpResponse import datetime def current (req): now = datetime. datetime. now () html = 'the current time is % s' % now return HttpResponse (html) def ahead (req, offset): # Here the offset is only the input value obtained from the url, variable names can actually be any try: offset = int (offset) alias t ValueError: raise Http404 () dt = datetime. datetime. now () + datetime. after timedelta (hours = offset) html = '% s hour, the time will change to % s' % (offset, dt) # After the offset hour, the time will change to dt return HttpResponse (html)

Related Article

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.