windows下apache+django

本文详细介绍了在Windows系统下如何安装并配置Apache服务器,以及如何将Django项目与Apache集成。内容包括安装Django、创建Django项目和应用、编写视图和模板,设置静态文件和接收用户数据,以及Apache服务器的安装和配置,最后讨论了Apache多应用集成的问题。
摘要由CSDN通过智能技术生成
安装django1.10.2
python -m pip install django


修改环境变量PATH
d:\python36\Script;


查看版本号
python -m django --version




检查是否安装成功,cmd下运行
C:\Users\Administrator>python -m django


Type '__main__.py help <subcommand>' for help on a specific subcommand.


Available subcommands:


[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata




安装pycharm用于开发python程序的ide
http://www.jetbrains.com/pycharm/download/download-thanks.html?platform=windows
----------------------------------------------------------------------------------
新建django项目


D:\workspace_python\mysite


项目的工程目录如下:
mysite/
mysite/
__init__.py
settings.py
urls.py
wsgi.py
templates
manage.py
------------------------------------
创建app(子模块)
在terminal控制台输入:
python manage.py startapp jkx
自动创建jkx文件夹
-------------------------------------
编写路由urls.py
from django.conf.urls import url
from django.contrib import admin
from jkx import views


urlpatterns = [
    #admin后台路由
    #url(r'^admin/', admin.site.urls),
    #添加路由
    url(r'index/',views.index)
]


----------------------------------------------
编写业务处理逻辑jkx/views.py
from django.shortcuts import render
from django.shortcuts import HttpResponse




# Create your views here.
def index(request):
    return HttpResponse('Hello word')


-------------------------------------------------
运行web服务
#在不影响其他模块的情况下创建表结构
python manage.py migrate
#检查语法错误
python manage.py validate
#启动服务器
python manage.py runserver


检查运行结果:
http://localhost:8000/index/


------------------------------------------------------------------
返回html
在templates中添加index.html页面,添加如下内容:
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>tese</title>
</head>
    <h1 style="background-color: antiquewhite;color: black">hello world</h1>
</html>




修改view.py
from django.shortcuts import render
from django.shortcuts import HttpResponse




# Create your views here.
def index(request):
    # return HttpResponse('Hello word')
    return render(request, 'index.html')
-----------------------------------------------------------------


添加静态文件
在mysite下新建static目录
其他插件也可以放到该目录下
js
imgs
css
plugins


需要在settings.py文件,配置新添加的静态文件


STATIC_URL = '/static/'
STATICFILES_DIRS=(
    os.path.join(BASE_DIR,'static'),
)






页面中引用js文件
<script src="/static/js/jquery-3.1.1.js"></script>


------------------------------------------------
接收用户发送数据
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值