zoukankan      html  css  js  c++  java
  • django官网手册学习 一

    对应手册Part1

    1,python -c "import os;print os.path" #python 直接运行字符串的方式。


    2,startproject

    1  django-admin.py startproject mysite

      创建一个项目。

    3,

    python manage.py startapp polls

      创建一个应用。


    3,Database setting

     1> 数据库设置关键字段:

        Engine: -– Either 'django.db.backends.sqlite3''django.db.backends.postgresql_psycopg2''django.db.backends.mysql', or'django.db.backends.oracle'

        Name: The name of your database.如果是sqlite3这样以文件形式任意存储的数据库 那么“'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),”

        User :用户名

        Password: 密码

      If you are not using SQLite as your database, additional settings such as USERPASSWORDHOST must be added.

      注:必须保证 python-mysqldb已经安装好。

        sudo apt-get install python-mysqldb

    生成数据库表

    python manage.py  syncdb

    生成应用中定义过的模块的sql语句,并不执行它。

    python manage.py sql polls

    提交模块中的变动(要先提交变得才能用syncdb)

    python manage.py makemigrations  #会在 migration文件夹下建立一个新文件。

    python manage.py sqlmigrate polls 0002 #根据migration文件夹下的文件下划线前缀生成相应的sql语句。

    python manage.py migrate  安装自建数据库。

      


    model :

      By running makemigrations, you’re telling Django that you’ve made some changes to your models (in this case, you’ve made new ones) and that you’d like the changes to be stored as a migration.


    shell调试:

      python manage.py shell

    %load_ext autoreload
    %autoreload 2  #ipython重新载入模块
    import django
    django.setup()

    1,调试数据库表model.  

    from polls.models import User

    2,增查改删 CRUD

      

    ''''''
    row = User(name='小明',age=13)
    row.save()
    ''''''
    row.delete()
    ''''''
    row.save()
    row.name='小王'
    row.save()
    ''''''
    data = User.objects.all()
    data[0].name #这个返回的是汉字ASCII编码。

        

  • 相关阅读:
    MVC在View中页面跳转
    javaEE之------ApectJ的切面技术===标签
    Service的生命周期
    Codeforces Round #253 (Div. 2)
    hdu 3183 A Magic Lamp(给一个n位的数,从中删去m个数字,使得剩下的数字组成的数最小(顺序不能变),然后输出)
    【转】理解红黑树
    概要设计注意事项
    C++ 初始化与赋值
    UE 的使用
    内存泄漏
  • 原文地址:https://www.cnblogs.com/canbefree/p/4083911.html
Copyright © 2011-2022 走看看