Django Learning 1

Source: Internet
Author: User

This Web framework can be well studied and I believe it will soon be used at work.

Related Files:

Settings. py

"""Django settings for djangoweb project.For more information on this file, seehttps://docs.djangoproject.com/en/1.7/topics/settings/For the full list of settings and their values, seehttps://docs.djangoproject.com/en/1.7/ref/settings/"""# Build paths inside the project like this: os.path.join(BASE_DIR, ...)import osBASE_DIR = os.path.dirname(os.path.dirname(__file__))# Quick-start development settings - unsuitable for production# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/# SECURITY WARNING: keep the secret key used in production secret!SECRET_KEY = ‘!v*++8l%=al$7=9)-mct$=!ig^e+9hv)k&iomr&[email protected]^-y‘# SECURITY WARNING: don‘t run with debug turned on in production!DEBUG = TrueTEMPLATE_DEBUG = TrueALLOWED_HOSTS = []# Application definitionINSTALLED_APPS = (    ‘django.contrib.admin‘,    ‘django.contrib.auth‘,    ‘django.contrib.contenttypes‘,    ‘django.contrib.sessions‘,    ‘django.contrib.messages‘,    ‘django.contrib.staticfiles‘,)MIDDLEWARE_CLASSES = (    ‘django.contrib.sessions.middleware.SessionMiddleware‘,    ‘django.middleware.common.CommonMiddleware‘,    ‘django.middleware.csrf.CsrfViewMiddleware‘,    ‘django.contrib.auth.middleware.AuthenticationMiddleware‘,    ‘django.contrib.auth.middleware.SessionAuthenticationMiddleware‘,    ‘django.contrib.messages.middleware.MessageMiddleware‘,    ‘django.middleware.clickjacking.XFrameOptionsMiddleware‘,)ROOT_URLCONF = ‘djangoweb.urls‘WSGI_APPLICATION = ‘djangoweb.wsgi.application‘TEMPLATE_DIRS = (    os.path.join(os.path.split(os.path.dirname(__file__))[0], ‘template‘),)# Database# https://docs.djangoproject.com/en/1.7/ref/settings/#databasesDATABASES = {    ‘default‘: {        ‘ENGINE‘: ‘django.db.backends.mysql‘,        ‘NAME‘: ‘djangodb‘,        ‘USER‘: ‘root‘,        ‘PASSWORD‘: ‘password‘,        ‘HOST‘: ‘127.0.0.1‘,        ‘PORT‘: ‘3306‘,        #‘ENGINE‘: ‘django.db.backends.sqlite3‘,        #‘NAME‘: os.path.join(BASE_DIR, ‘db.sqlite3‘),    }}# Internationalization# https://docs.djangoproject.com/en/1.7/topics/i18n/LANGUAGE_CODE = ‘en-us‘TIME_ZONE = ‘Asia/Shanghai‘USE_I18N = TrueUSE_L10N = TrueUSE_TZ = True# Static files (CSS, JavaScript, Images)# https://docs.djangoproject.com/en/1.7/howto/static-files/PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))STATIC_ROOT = os.path.join(os.path.dirname(PROJECT_PATH), ‘static‘)STATICFILES_DIRS = (    ("css", os.path.join(STATIC_ROOT, ‘css‘)),    ("js", os.path.join(STATIC_ROOT, ‘js‘)),    ("img", os.path.join(STATIC_ROOT, ‘img‘)),)STATIC_URL = ‘/static/‘

URLs. py

from django.conf.urls import patterns, include, urlfrom django.contrib import adminfrom djangoweb.view import hello,homepage,ctime,current_datetimeurlpatterns = patterns(‘‘,    # Examples:    # url(r‘^$‘, ‘djangoweb.views.home‘, name=‘home‘),    # url(r‘^blog/‘, include(‘blog.urls‘)),    url(r‘^admin/‘, include(admin.site.urls)),    url(r‘^hello/$‘, hello),    url(r‘^$‘, homepage),    url(r‘^time/$‘, ctime),    url(r‘^time/(\d{1,2})/$‘, ctime),    url(r‘current_datetime/$‘, current_datetime),)

View. py

from django.http import HttpResponseimport datetimefrom django import templatedef current_datetime(req):    now = datetime.datetime.now()    fp = open(‘D:/py/django/djangoweb/template/mytemplate.html‘)    t = template.Template(fp.read())    fp.close()    html = t.render(template.Context({‘current_date‘:now}))    return HttpResponse(html)def ctime(req, num):    try:        num = str(num)    except ValueError:        raise Http404        cutime = datetime.datetime.now()    txt = "it‘s %s." % cutime    txt2 = "url is [http://127.0.0.1:8000/time/%s/]" % num    assert False    return HttpResponse(txt + txt2)def hello(req):    return HttpResponse("

Django Learning 1

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.