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 ...
随机推荐
- Java Thread Status(转)
public static enum Thread.State extends Enum<Thread.State>线程状态.线程可以处于下列状态之一: 1.NEW 至今尚未启动的线程的 ...
- bzoj1143
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1143 首先用传递闭包,知道一个点是否可以到达另一个点,即mp[i][j]==1表示i可以到j: ...
- hdu5017:补题系列之西安网络赛1011
补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为m ...
- PHP null常量和null字节的区别
在学习isset()时,看到了这句话:“如果已经使用 unset() 释放了一个变量之后,它将不再是 isset().若使用 isset() 测试一个被设置成 NULL 的变量,将返回 FALSE.同 ...
- Thinkphp显示系统常量信息的方法(php的用法)
输入 :public function Main() { dump(get_defined_constants(true)); }显示系统信息, 其中: 'APP_PATH' ...
- 使用教程 - BestSync同步软件 - SQL2008R2 数据库定时备份解决方案
需求: 1. 某公司的管理软件,数据库为SQL2008R2.2. 将整个数据库作为一个文件,定时同步到FTP 服务器3. 需要有多个备份,每同步一次,都备份上次的文件到备 ...
- 优化移动体验的HTML5技巧
简介 连轴转的刷新,不断变向的页面转换,以及tap事件的周期性的延迟仅仅是现在移动web环境令人头疼事情的一小部分.开发者正试图尽可能的靠近原生应用,但却经常被各种兼容问题,系统复位,和僵化的框架打乱 ...
- Qt 图形特效(Graphics Effect)介绍
原文链接:Qt 图形特效(Graphics Effect)介绍 QGraphicsEffect也是Qt-4.6引入的一个新功能.它让给图形元素QGraphicsItem增加更佳视觉效果的编程变得非常简 ...
- EasyInvoice 使用教程 - (1) 认识 EI
原视频下载地址:EI 主界面介绍 1. 主界面截图 2. 基础资料界面截图 3. 管理员 界面截图
- io系统
一.浅谈io系统 io系统的结构化思想是:输入-转换流-装饰器-输出. 对于字节流来说,常见的结构类为: package com.handchina.yunmart.middleware.servic ...