Django的安装使用,以及建立本地网站

一、安装Django

pip install django

完成后即可

二、pycharm 建立django

点击file ——>new project 选择django项目——>more setting填写appname

生成以下项目结构

-views.py中处理视图逻辑,一般为大量函数方法。一般被urls处理调用,收到请求,返回templates模板内容

-urls中设置url指定网关路径,调用的视图中的具体方法

tips:html文件中的js,cs,img,font等放在新建的static文件夹中,并在setting.py末尾添加一下代码

STATIC_URL = '/static/'
HERE = os.path.dirname(os.path.abspath(__file__))
HERE = os.path.join(HERE, '../')
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(HERE, 'static/'),
)

在html中调用方式稍作修改

原文地址:https://www.cnblogs.com/wang666/p/7911092.html