DJANGO学习一则
这个WEB框架,可以好好研究,相信很快就会用在工作上的。
相关文件:
settings.py
"""
Django settings for djangoweb project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_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&jtlul-@6^-y'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_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/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'djangodb',
'USER': 'root',
'PASSWORD': 'password',
'HOST': '127.0.0.1',
',
#'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 = True
USE_L10N = True
USE_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, url
from django.contrib import admin
from djangoweb.view import hello,homepage,ctime,current_datetime
urlpatterns = 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 HttpResponse
import datetime
from django import template
def 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("<h1>Hello, python django world!</h1>")
def homepage(req):
return HttpResponse("<h1>This is homepage.</h1>")







DJANGO学习一则的更多相关文章
- 今天主要推荐一下django学习的网址!
前言:每个月忙碌的头20天后,在上班时间投入到django理论学习的过程中,花了差不多3天时间简单的研究了一下django,着实废了我不少脑细胞. 采用虫师前辈的一张图和话: 如果你把这过程梳理清晰了 ...
- Django 学习笔记之四 QuerySet常用方法
QuerySet是一个可遍历结构,它本质上是一个给定的模型的对象列表,是有序的. 1.建立模型: 2.数据文件(test.txt) 3.文件数据入库(默认的sqlite3) 入库之前执行 数据库同步命 ...
- Django 学习笔记之三 数据库输入数据
假设建立了django_blog项目,建立blog的app ,在models.py里面增加了Blog类,同步数据库,并且建立了对应的表.具体的参照Django 学习笔记之二的相关命令. 那么这篇主要介 ...
- Django学习系列之Form基础
Django学习系列之Form基础 2015-05-15 07:14:57 标签:form django 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追 ...
- Django学习笔记(五)—— 表单
疯狂的暑假学习之 Django学习笔记(五)-- 表单 參考:<The Django Book> 第7章 1. HttpRequest对象的信息 request.path ...
- Django学习笔记(三)—— 型号 model
疯狂暑期学习 Django学习笔记(三)-- 型号 model 參考:<The Django Book> 第5章 1.setting.py 配置 DATABASES = { 'defaul ...
- django学习之Model(二)
继续(一)的内容: 1-跨文件的Models 在文件头部import进来,然后用ForeignKey关联上: from django.db import models from geography.m ...
- Python框架之Django学习
当前标签: Django Python框架之Django学习笔记(十四) 尛鱼 2014-10-12 13:55 阅读:173 评论:0 Python框架之Django学习笔记(十三) 尛 ...
- Django 学习笔记(二)
Django 第一个 Hello World 项目 经过上一篇的安装,我们已经拥有了Django 框架 1.选择项目默认存放的地址 默认地址是C:\Users\Lee,也就是进入cmd控制台的地址,创 ...
- Django 学习笔记(五)模板标签
关于Django模板标签官方网址https://docs.djangoproject.com/en/1.11/ref/templates/builtins/ 1.IF标签 Hello World/vi ...
随机推荐
- cf B. Vasya and Public Transport
http://codeforces.com/contest/355/problem/B #include <cstdio> #include <cstring> #includ ...
- OpenJTAG+Eclipse 3.5+GDB+Mini2440图文教程
OpenJTAG+Eclipse 3.5+GDB+Mini2440图文教程 OpenJTAG与JLink的区别比较: 相同点:都同时具备USB转JTAG.USB转串口功能 差别: 1. 操作系统: O ...
- c语言typedef之数组运用
#include <stdio.h> #include <stdlib.h> typedef ];//int arr[4]取一个别名 arr b c就是int b[4] int ...
- poj 1236 Network of Schools(tarjan+缩点)
Network of Schools Description A number of schools are connected to a computer network. Agreements h ...
- python数据类型-布尔值
布尔是计算机里最基本的判断单位,布尔只有两个值:真或假,即True False,也就是1或0. 在以后学习流程控制时会经常用到布尔值. 先来看简单的小例子: >>> 1+1 > ...
- DDMS files not found: tools\hprof-conv.exe
最近在Eclipse下每次更新ADT和SDK后都报一些错误,比如 DDMS files not found: D:\android-sdk-windows-1.6_r1\android-sdk-win ...
- 曾经的足迹——对Linux CAN驱动的理解(1)
在Ti的AM335X系列Cortext-A8芯片中,CAN模块采用D_CAN结构,实质即两路CAN接口. 在此分享一下对基于AM335X的Linux CAN驱动源码的理解.下面来分析它的驱动源码及其工 ...
- oracle 格式化数字 to_char
转:http://blog.csdn.net/chinarenzhou/article/details/5748965 Postgres 格式化函数提供一套有效的工具用于把各种数据类型(日期/时间,i ...
- 执行eclipse,迅速failed to create the java virtual machine。
它们必须在一排,否则会出现The Eclipse executable launcher was unable to locate its companion shared library的错误 打开 ...
- swift调用相机和相册
简单实现swift调用相机和相册的功能,分享代码与学习swift的童鞋共同进步 import UIKit class ViewController: UIViewController,UIImageP ...