1.创建Django项目做基本的配置步骤
Pycharm->new->New Project


2.基本的配置
settings.py-->STATIC_URL = '/static/'后面新增
STATICFILES_DIRS = (
os.path.join(BASE_DIR,'static'),
)


配置好后新增文件夹在项目文件夹下,命名为static
3.配置urls的新页面
1).新增语句 from django.conf.urls import url
from app01 import views
2).配置url链接
url(r'^upload.html$',views.upload),


4.写应用中配置的views方法
def upload(request):
#中间可以新增各种各样的逻辑判断方法
return render(request,'upload.html')


5.配置HTML文件

<!DOCTYPE html>
<html lang="en">
{% load staticfiles %}
<head>
<meta charset="UTF-8">
<title>Blog_test</title>
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'bootstrap/js/bootstrap.js' %}">
<link rel="stylesheet" href="{% static 'bootstrap/fonts/glyphicons-halflings-regular.ttf' %}">
<link rel="stylesheet" href="{% static 'font-awesome/web-fonts-with-css/css/fontawesome-all.min.css' %}">
<script SRC="/static/Echarts/echarts.js"></script>
</head>
<body>
{# _______________________________________导航条__________________________________________________________#}
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">我的博客</a>
</div> <!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">首页<span class="sr-only">(current)</span></a></li>
<li><a href="#">我的随笔</a></li>
<li><a href="#">我的文章</a></li>
<li><a href="#">管理</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">统计<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">随笔:</a></li>
<li><a href="#">文章:</a></li>
<li><a href="#">评论:</a></li>
<li><a href="#">引用:</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">百度一下</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">联系我</a></li>
<li><a href="http://127.0.0.1:8000/test.html">测--试</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">排行榜 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">阅读排行榜</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">评论排行榜</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">推荐排行榜</a></li>
</ul>
</li>
{# _____________________________________模态框(登录界面)___________________________________________________#}
<li style="padding-top: 2%">
<!-- Button trigger modal -->
<button type="button" class="btn btn-inverse" data-toggle="modal" data-target="#myModal">
登录
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">用户登录</h4>
</div>
<form action="index.html" method="post" id="fm">
<div class="modal-body">
<p><i class="fa fa-user"><input name="username" placeholder="用户名" type="text" style="height: 30px;width: 260px;"/></i></p>
<p><i class="fa fa-unlock-alt"><input name="password" placeholder="密码" type="password" style="height: 30px;width: 260px"/></i></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="submit" class="btn btn-primary" onclick="submitlogin()">登录</button>
</div></form>
</div>
</div>
</div>
</li>
{# _________________________________________________________________________________________________#}
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<script src="/static/js/jquery-3.3.1.min.js">
</script>
<script>
function submitlogin() {
$.ajax({
url:'index.html',
type:'POST',
data:$('#fm').serialize(),
success:function (arg) {
console.log(arg);
}
})
}
</script>
<script src="/static/bootstrap/css/bootstrap.css"></script>
<script src="/static/bootstrap/js/bootstrap.js" type="text/javascript"></script>
</body>
</html>

index.html

from django.shortcuts import render,HttpResponse
from Blog.models import UserInfo
# Create your views here.
def index(request):
return render(request,'index.html')
def test(request):
return render(request,'test.html')
def login(request):
if request.method == 'GET':
return render(request,'index.html')
else:
u = request.POST.get('username')
p = request.POST.get('password')
users = UserInfo.objects.filter(username=u,password=p). \
values('nid', 'nickname','username', 'email','avatar',).first()
if users:
return render(request,'index.html')
else:
return render(request,'test.html')

views.py

from django.db import models

# Create your models here.
class UserInfo(models.Model):
"""
用户表
"""
def __str__(self):
return self.username
nid = models.BigAutoField(primary_key=True)
username = models.CharField(verbose_name='用户名', max_length=32, unique=True)
password = models.CharField(verbose_name='密码', max_length=64)
nickname = models.CharField(verbose_name='昵称', max_length=32)
email = models.EmailField(verbose_name='邮箱', unique=True)
avatar = models.ImageField(verbose_name='头像')

models.py

"""
Django settings for MyBlog project. Generated by 'django-admin startproject' using Django 2.0.5. For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/ For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
""" import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'tz)owazxyz+h!ysgs6=84(s__x!7zl!^+#5k-qk#iyw$nkz^+d' # SECURITY WARNING: don't run with debug turned on in production!
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',
'Blog.apps.BlogConfig',
] MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ROOT_URLCONF = 'MyBlog.urls' TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
] WSGI_APPLICATION = 'MyBlog.wsgi.application' # Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'cms',
'USER': 'root',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '',
}
} # Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
] # Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/ STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR,'static'),
)

settings.py

【Django】创建后的基本操作的更多相关文章

  1. MySQL在Django框架下的基本操作(MySQL在Linux下配置)

    [原]本文根据实际操作主要介绍了Django框架下MySQL的一些常用操作,核心内容如下: ------------------------------------------------------ ...

  2. 利用django创建一个投票网站(一)

    这是教程的原始链接:http://django-intro-zh.readthedocs.io/zh_CN/latest/part1/ 创建你的第一个 Django 项目, 第一部分 来跟着实际项目学 ...

  3. 用django创建一个简单的sns

    用django创建一个简单的sns 1.首先创建一个工程newsns django-admin.py startproject newsns 在工程目录下新建一个文件夹templates,在该文件夹下 ...

  4. Django创建博客

    拜读http://www.cnblogs.com/fnng/p/3737964.html 后自操作步骤,mark一下 我的想法: modles.py中只负责添加类,定义数据结构,至于将该类添加到adm ...

  5. django创建工程,用命令

    django创建工程的命令 >>python C:\Python33\Lib\site-packages\django\bin\django-admin.py startproject p ...

  6. django创建第一个项目helloworld

    环境:centos 7,已安装python 3.6环境 1.安装django并创建django第一个项目 1.1.使用pip安装django# pip install Django或指定安装版本# p ...

  7. linux下配置python环境 django创建helloworld项目

    linux下配置python环境 1.linux下安装python3 a. 准备编译环境(环境如果不对的话,可能遇到各种问题,比如wget无法下载https链接的文件) yum groupinstal ...

  8. Django创建基本流程

    Django创建基本流程 1.创建工程:django-admin startproject 工程名 2.创建应用:python manage.py startapp 应用名 3.激活项目:修改sett ...

  9. Django创建数据库常用字段及参数

    Django创建数据库常用字段及参数 常用字段 1.models.AutoField 自增列= int(11) 如果没有的话,默认会生成一个名称为 id 的列,如果要显示的自定义一个自增列,必须将给列 ...

随机推荐

  1. Git 常用命令速查(转载)

    git branch 查看本地所有分支git status 查看当前状态 git commit 提交 git branch -a 查看所有的分支git branch -r 查看远程所有分支git co ...

  2. 用haproxy实现nginx的proxy_pass转发功能

    公司的网站有个需求,主站点上有两个URL,没有在本地nginx上配置,而是在另一台主机的nginx上配置的站点.如果使用nginx作为反向代理,可以使用proxy_pass指令转发对这两个URL的请求 ...

  3. 洛谷 P1137 旅行计划 (拓扑排序+dp)

    在DAG中,拓扑排序可以确定dp的顺序 把图的信息转化到一个拓扑序上 注意转移的时候要用边转移 这道题的dp是用刷表法 #include<bits/stdc++.h> #define RE ...

  4. CodeForcesGym 100641D Generalized Roman Numerals

    Generalized Roman Numerals Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on  ...

  5. 清除eclipse中的SVN账号信息

    清除eclipse中的SVN账号信息 参考了:http://blog.csdn.net/ningtieming/article/details/60469346 需要先在资源管理器中使用Tortois ...

  6. An internal error occurred during: &quot;Building workspace&quot;. java.lang.StackOverflowError

    1 错误描写叙述 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveW91MjNoYWk0NQ==/font/5a6L5L2T/fontsize/400/fi ...

  7. 图像滤镜艺术---保留细节的磨皮之C#程序实现

    上一篇博文"保留细节的磨皮滤镜之PS实现"一文中.我简介了本人自己总结的一种非常easy的磨皮滤镜,这个滤镜在磨光皮肤的同一时候,会保留非常不错的细节,今天,我将介绍使用C#程序实 ...

  8. 验证DG最大性能模式下使用ARCH/LGWR及STANDBY LOG的不同情况

    总结:  --两台单实例数据库做DG,数据库版本号10.2.0.1.0 1.主库配置为:arch async,备库无STANDBY LOG. 日志中会有:RFS[4]: No standby redo ...

  9. 为什么网络银行不支持GNU/Linux操作系统下的浏览器操作

    当年Linux没出时.银行就開始信息化建设了. 所为信息化,就是指用计算机工作了.服务客户了. 顺带着,慢慢的建server,连网(内部网).外网(网上银行) 这样下来, unix, dos, win ...

  10. 痛苦的人生——JRuby on Rails的开发与部署小记

    最近单位领导部署了一项开发用户自助服务系统的任务,该任务有且仅有我一人独立完成——哈哈,十分美妙的工作呢. 恰巧楼主最近被Ruby的美妙特性所迷惑,于是义无反顾地投入到Ruby on Rails的怀抱 ...