search

Home  >  Q&A  >  body text

python - 自己创建的django package怎么生成模型创建脚本?

高洛峰高洛峰2889 days ago394

reply all(2)I'll reply

  • PHPz

    PHPz2017-04-18 09:32:48

    You can write a startproject command yourself
    I wrote a flask startproject: mana
    The general idea is as follows

    1. Write a project prototype locally (you can add manage.py, User model with Auth)

    2. Then consider the dynamic part (the part of the generated project that may change, such as the project name), and mark the dynamic part with an annotation format similar to #{{ xxx }}

    3. Then write the command (click is recommended). The key is to use python os.walk to traverse your prototype (note the use of absolute paths), copy it to your generated project, and dynamically read the partial file replacement#{{ xxx }}.

    4. So you can

      $ yourcommand startproject YourDjangoProject
      $ cd YourDjangoProject  (你想要的项目原型: 含manage.py, 含基本的User模型)
      $ python manage.py makemigrations
      $ python manage.py migrate
      
      

    Cookiecutter is a scaffolding. If you are not satisfied with its function, you can write one yourself.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:32:48

    If you want to know how to deal with it, just message me. No one is interested in this problem, and I am too lazy to write how to deal with it.

    reply
    0
  • Cancelreply