美文网首页
Pinax (Django 2.0.2 快速搭建骨架)

Pinax (Django 2.0.2 快速搭建骨架)

作者: 金哲虎 | 来源:发表于2018-03-13 17:42 被阅读301次

    它就是一个Django开发骨架,方便我们快速搭建一个网站 参考地址

    • pip install pinax-cli
    • 命令格式: pinax start <kind> <project_name>
    • 解决编码问题,执行下面2行代码
    export LC_ALL=C.UTF-8
    export LANG=C.UTF-8
    
    • pinax start account mysite #这个动作等于下面的操作
    pip install Django==2.0
    django-admin startproject --template=https://github.com/pinax/pinax-starter-projects/zipball/account mysite
    
    • pip install -r requirements.txt
    • ./manage.py migrate
    • ./manage.py loaddata sites
    • ./manage.py createsuperuser
    • npm i 不要急着执行,先去下面(遇到的小坑)看一下!
    • npm run dev

    • pinax projects #列出可以安装使用的骨架项目<kind>
    Release Project
    ------- ---------------
      4.0.3 account
      4.0.3 blog
      2.0.3 company
            documents
            social-auth
      4.0.3 static
      4.0.3 stripe
            team-wiki
      3.0.3 waitinglist
            wiki
      4.0.3 zero
    

    • pinax还有很多扩展app 参考地址
    • 可以使用这些扩展app快速搭建一个网站

    遇到的小坑

    开发场景: 开发机Windows 7+本地Docker

    • Windows 7 编写代码,在本地Docker上测试运行pinax。Docker Container是Ubuntu16.04 64位。

    • Container和本地磁盘G盘进行了挂载。

    • pinax使用了sass编写css,所以需要node-sass模块来编译这些文件。

    • 在docker container上创建项目后,npm install安装node模块时安装在本地的是node-sass for windows,
      并非是node-sass for linux。所以这里会发生问题,也折腾了我一下午的时间。

    • 解决方法

      • pinax生成项目后,执行 npm install后,进入windows系统的pinax项目node_modules/目录里去删除node-sass目录。
      • 或者先打开package.json文件,把node-sass删除掉!然后在进行 npm install
      • 然后在docker container上安装node-sass模块。具体方法我已经发布了传送门
      • 然后 npm run dev 可以正常启动了!
    • 还没有完,再啰嗦几句。

      • 打开package.json文件后,可以看到关于browser-sync的配置,如下:
    "dev:browser-sync": "browser-sync start --no-open --proxy localhost:8000 --files \"static/dist/js/*.js, static/dist/css/*.css\"",
    
    • --proxy localhost:8000 在这里直接可以修改IP和端口,可以这样设置 --proxy 0.0.0.0:8000 原因你懂得。
    • 我的package.json内容如下
    {
      "repository": {
        "type": "git",
        "url": "https://github.com/pinax/pinax-project"
      },
      "scripts": {
        "clean": "rm -rf static/dist && mkdir -p static/dist/js && mkdir -p static/dist/css && mkdir -p static/dist/images",
        "build:js": "browserify -t [ babelify --presets [ env ] ] -t envify -o static/dist/js/site.js static/src/js/index.js",
        "build:css": "node-sass static/src/scss/index.scss static/dist/css/app.css",
        "copy:images": "cp -r static/src/images/* static/dist/images/ 2>/dev/null || :",
        "optimize:js": "uglifyjs static/dist/js/site.js -m -c warnings=false -o static/dist/js/site.js",
        "optimize:css": "cssnano static/dist/css/app.css static/dist/css/app.css",
        "optimize": "npm run optimize:js && npm run optimize:css",
        "watch:test": "onchange static/src/js/**/*.js -- npm run test",
        "watch:lint": "onchange static/src/js/**/*.js -- npm run lint",
        "watch:js": "watchify -t [ babelify --presets [ env ] ] -t envify static/src/js/index.js -o 'exorcist static/dist/js/site.js.map > static/dist/js/site.js' -dv",
        "watch:css": "node-sass static/src/scss/index.scss static/dist/css/app.css --watch -r",
        "build": "npm run clean && concurrently \"npm run build:js\" \"npm run build:css\" \"npm run copy:images\" && npm run optimize",
        "watch": "npm run clean && npm run copy:images && npm run build:css && concurrently --raw \"npm run watch:lint\" \"npm run watch:js\" \"npm run watch:css\"",
        "dev:browser-sync": "browser-sync start --no-open --proxy 0.0.0.0:8000 --files \"static/dist/js/*.js, static/dist/css/*.css\"",
        "dev": "concurrently --raw \"./manage.py runserver 0:8000\" \"npm run watch\" \"npm run dev:browser-sync\"",
        "lint": "eslint static/src/**/**/*.js",
        "test": "mocha --recursive --compilers js:babel-register static/src/tests/index.js",
        "compile": "NODE_ENV=production npm run clean && concurrently \"npm run copy:images\" \"npm run build:js\" \"npm run build:css\"",
        "heroku-postbuild": "npm run compile && npm run optimize"
      },
      "license": "UNLICENSED",
      "dependencies": {
        "babel-core": "6.26.0",
        "babel-preset-env": "1.6.1",
        "babelify": "8.0.0",
        "bootstrap": "4.0.0",
        "browser-sync": "2.23.6",
        "browserify": "15.2.0",
        "chai": "4.1.2",
        "concurrently": "3.5.1",
        "cssnano": "3.10.0",
        "cssnano-cli": "1.0.5",
        "envify": "4.1.0",
        "eslint": "4.16.0",
        "eslint-plugin-babel": "4.1.2",
        "exorcist": "1.0.0",
        "jquery": "3.3.1",
        "jsdom": "11.6.2",
        "jsdom-global": "3.0.2",
        "mocha": "5.0.0",
        "node-sass": "^4.7.2",
        "onchange": "3.3.0",
        "uglify-js": "3.3.9",
        "watchify": "3.10.0"
      }
    }
    
    
    • 我修改的内容有两处,--proxy 0.0.0.0:8000./manage.py runserver 0:8000
      • "dev:browser-sync": "browser-sync start --no-open --proxy 0.0.0.0:8000 --files "static/dist/js/.js, static/dist/css/.css"",
      • "dev": "concurrently --raw "./manage.py runserver 0:8000" "npm run watch" "npm run dev:browser-sync"",
    • 好吧,就这样吧!

    相关文章

      网友评论

          本文标题:Pinax (Django 2.0.2 快速搭建骨架)

          本文链接:https://www.haomeiwen.com/subject/diqzfftx.html