$django-admin.py startproject web2
$cd web2/
$python manage.py startapp blog
$vim web2/settings.py

注意settings.py以下两个部分,首先要配置数据库,其次要在INSTALLED_APP里添加刚才新建的app

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' o
'NAME': 'dj_db01', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'root',
'PASSWORD': '',
'HOST': 'localhost', # Empty for localhost through domain sockets
'PORT': '', # Set to empty string for default.
}
}
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
)

接下来编辑models.py

$vim blog/models.py

from django.db import models

在mysql里新建对应的数据里

mysql> create database dj_db01 default charset utf8;

现在可以自动生成各种表啦

$ python manage.py syncdb

现在编辑以下url的config

$vim web1/urls.py
from django.conf.urls import patterns, include, url 

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover() urlpatterns = patterns('',
# Examples:
# url(r'^$', 'web1.views.home', name='home'),
# url(r'^web1/', include('web1.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
url(r'^blog/$','blog.views.index'),
)

$mkdir blog/static/images

然后从别的地方拷贝过来一张图,这里我拷贝过来的img2.jpg

接下来编辑一下页面

$mkdir blog/templates
$vim blog/templates/index.html
 <h1>hello world</h1>
<img src='/static/images/img2.jpg'/>

运行一下

python manage.py runserver 3900

白手起家搭建django app的更多相关文章

  1. Pycharm搭建Django开发环境

    Pycharm搭建Django开发环境 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我们大家都知道Django是python都一个web框架,因此大家需要自行安装python环境 ...

  2. 从0到1搭建移动App功能自动化测试平台(2):操作iOS应用的控件

    转自:http://debugtalk.com/post/build-app-automated-test-platform-from-0-to-1-Appium-interrogate-iOS-UI ...

  3. 从0到1搭建移动App功能自动化测试平台(0):背景介绍和平台规划

    本文作者: 伯乐在线 - debugtalk .未经作者许可,禁止转载!欢迎加入伯乐在线 专栏作者. 转载地址:http://blog.jobbole.com/101221/ 背景 最近新加入DJI的 ...

  4. Windows7下搭建Django运行环境

    一直都是在Linux环境下搭建django的运行环境,开学因为需要叫前端的同学帮忙修改模板,所以需要在Windows下搭建起运行环境,想来PHP倒是有不少集成开发环境,Python倒是少的可怜…只在w ...

  5. [个人网站搭建]·Django增加评论功能(Python3)

    [个人网站搭建]·Django增加评论功能 个人主页--> https://xiaosongshine.github.io/ 个人网站搭建github地址:https://github.com/ ...

  6. 在 ubuntu18.04 中搭建 Django 开发环境

    在Ubuntu 18.04 安装 python3.pip3.pycharm,搭建 Django 开发环境. 1.安装 python3 pip3 sudo apt-get install python3 ...

  7. Python-Django 第一个Django app

    第一个Django app   by:授客 QQ:1033553122 测试环境: Python版本:python-3.4.0.amd64 下载地址:https://www.python.org/do ...

  8. Django APP打包重用

    引言 有时候,我们需要将自己写的app分发(dist)给同事,分享给朋友,或者在互联网上发布,这都需要打包.分发我们的app. Django的子系统重用是基于app级别的.也就是一个项目可以包含多个互 ...

  9. 搭建Django项目

    命令行搭建Django项目 1.安装django 在指定解释器环境下安装django 1.11.9 在真实python3环境下: pip3 install django==1.11.9 在虚拟环境下: ...

随机推荐

  1. express 笔记 app.helpers 和 app.locals

    app.helpers 和app.dynamicHelpers 是express2.X使用的 分别为静态/动态 视图助手通过其注册函数, 例如 app.helpers({ <span style ...

  2. Linq表达式开窍

    static IQueryable<T> GetPageList<T,TKey>(Expression<Func<T,bool>> whereLambd ...

  3. Beta项目冲刺汇总贴

    第一天 http://www.cnblogs.com/Allenbi/p/5003704.html 第二天 http://www.cnblogs.com/Allenbi/p/5020820.html ...

  4. Struts2 数据校验流程

  5. UVA 540 stl

    Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...

  6. Java 缓存技术

    以下仅是对map对方式讨论.没有对点阵图阵讨论.作缓存要做以下2点:  1:清理及更新缓存时机的处理: . 虚拟机内存不足,清理缓存 .. 缓存时间超时,或访问次数超出, 启动线程更新 2:类和方法的 ...

  7. BZOJ-2326 数学作业 矩阵乘法快速幂+快速乘

    2326: [HNOI2011]数学作业 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1564 Solved: 910 [Submit][Statu ...

  8. angularjs-$interval使用

    1. 简单使用 var app = angular.module("app",[]); app.controller("AppCtrl", function($ ...

  9. 微信支付(APP)集成时碰到的问题(.net提示“无权限”、iOS跳转到微信支付页面中间只有一个“确定”按钮)

    直入主题之前,请容我吐槽一下微*的官方东西:ASDFQ%#$%$#$%^FG@#$%DSFQ#$%.......:吐槽玩了!大家心照就好. 要完成手机APP跳转到微信的APP进行微信支付,需要进行如下 ...

  10. tarjan算法求强连通分量

    先上代码: #include <iostream> #include <cstring> #include <vector> #include <stack& ...