• 跟老齐学Python Django实战 1/n Second edition


     https://docs.djangoproject.com/en/2.2/intro/tutorial01/

    virtualenv lqidjango
    source bin/activate
    
    pip3 install Django
    

      

      --> pass

                # but can't find the django-admin.py, "find|grep django-admin"

    django-admin startproject mysite
    

      --> fail

              

    (lqidjango) cor@debian:~/lqidjango$ django-admin startproject mysite
    bash: django-admin: command not found
    

      

    python3 -m django startproject  mysite
    

      --> pass

    #sudo apt-get install tree
    (lqidjango) cor@debian:~/lqidjango/mysite$ tree
    .
    ├── manage.py
    └── mysite
        ├── __init__.py
        ├── settings.py
        ├── urls.py
        └── wsgi.py
    
    1 directory, 5 files
    

      #

    (lqidjango) cor@debian:~/lqidjango/mysite$ python3 manage.py runserver
    Watching for file changes with StatReloader
    Performing system checks...
    
    System check identified no issues (0 silenced).
    
    You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
    Run 'python manage.py migrate' to apply them.
    
    April 23, 2020 - 03:01:43
    Django version 2.2.12, using settings 'mysite.settings'
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CONTROL-C.
    Error: That port is already in use.
    
      #sudo apt-get install net-tools
    cor@debian:~/webscrappython/Web_Scraping_with_Python/downloadAprial7th/wswp-code-9e6b82b47087/chapter08$ sudo apt-get install net-tools
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
      icedtea-netx icedtea-netx-common linux-image-4.9.0-8-amd64
    Use 'sudo apt autoremove' to remove them.
    The following NEW packages will be installed:
      net-tools
    0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
    Need to get 248 kB of archives.
    After this operation, 963 kB of additional disk space will be used.
    Get:1 http://mirrors.tuna.tsinghua.edu.cn/debian stretch/main amd64 net-tools amd64 1.60+git20161116.90da8a0-1 [248 kB]
    Fetched 248 kB in 2s (92.8 kB/s)                             
    Selecting previously unselected package net-tools.
    (Reading database ... 272538 files and directories currently installed.)
    Preparing to unpack .../net-tools_1.60+git20161116.90da8a0-1_amd64.deb ...
    Unpacking net-tools (1.60+git20161116.90da8a0-1) ...
    Processing triggers for man-db (2.7.6.1-2) ...
    Setting up net-tools (1.60+git20161116.90da8a0-1) ...
    cor@debian:~/webscrappython/Web_Scraping_with_Python/downloadAprial7th/wswp-code-9e6b82b47087/chapter08$ sudo netstat -anutp|grep 8000
    tcp6       0      0 :::8000                 :::*                    LISTEN      1804/docker-proxy
    

      

    #

    (lqidjango) cor@debian:~/lqidjango/mysite$ python3 manage.py runserver 7000
    Watching for file changes with StatReloader
    Performing system checks...
    
    System check identified no issues (0 silenced).
    
    You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
    Run 'python manage.py migrate' to apply them.
    
    April 23, 2020 - 03:37:15
    Django version 2.2.12, using settings 'mysite.settings'
    Starting development server at http://127.0.0.1:7000/
    Quit the server with CONTROL-C.
    

      

    Start APP

    python3 manage.py startapp blog
    (lqidjango) cor@debian:~/lqidjango/mysite$ tree
    .
    ├── db.sqlite3
    ├── manage.py
    └── mysite
        ├── __init__.py
        ├── __pycache__
        │   ├── __init__.cpython-35.pyc
        │   ├── settings.cpython-35.pyc
        │   ├── urls.cpython-35.pyc
        │   └── wsgi.cpython-35.pyc
        ├── settings.py
        ├── urls.py
        └── wsgi.py
    
    2 directories, 10 files
    (lqidjango) cor@debian:~/lqidjango/mysite$ python3 manage.py startapp blog
    (lqidjango) cor@debian:~/lqidjango/mysite$ tree
    .
    ├── blog
    │   ├── admin.py
    │   ├── apps.py
    │   ├── __init__.py
    │   ├── migrations
    │   │   └── __init__.py
    │   ├── models.py
    │   ├── tests.py
    │   └── views.py
    ├── db.sqlite3
    ├── manage.py
    └── mysite
        ├── __init__.py
        ├── __pycache__
        │   ├── __init__.cpython-35.pyc
        │   ├── settings.cpython-35.pyc
        │   ├── urls.cpython-35.pyc
        │   └── wsgi.cpython-35.pyc
        ├── settings.py
        ├── urls.py
        └── wsgi.py
    
    4 directories, 17 files
    

      #

    4 directories, 17 files
    (lqidjango) cor@debian:~/lqidjango/mysite$ python3 manage.py   makemigrations
    Traceback (most recent call last):
      File "manage.py", line 21, in <module>
        main()
      File "manage.py", line 17, in main
        execute_from_command_line(sys.argv)
      File "/home/cor/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
        utility.execute()
      File "/home/cor/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 357, in execute
        django.setup()
      File "/home/cor/.local/lib/python3.5/site-packages/django/__init__.py", line 24, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "/home/cor/.local/lib/python3.5/site-packages/django/apps/registry.py", line 114, in populate
        app_config.import_models()
      File "/home/cor/.local/lib/python3.5/site-packages/django/apps/config.py", line 211, in import_models
        self.models_module = import_module(models_module_name)
      File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 986, in _gcd_import
      File "<frozen importlib._bootstrap>", line 969, in _find_and_load
      File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 673, in exec_module
      File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
      File "/home/cor/lqidjango/mysite/blog/models.py", line 7, in <module>
        class BlogArticles(models.Model):
      File "/home/cor/lqidjango/mysite/blog/models.py", line 9, in BlogArticles
        author = models.ForeignKey(User, on_delete=Models.CASCADE, related_name="blog_posts")
    NameError: name 'Models' is not defined
    

      #

    (lqidjango) cor@debian:~/lqidjango/mysite$ find |grep models.py
    ./blog/models.py
    

      it seems that models.py is under "blog" while mange.py is not, I think I met  this before in another book.

  • 相关阅读:
    [SCOI2009] Windy数
    [P1361] 小M的作物
    Wannafly Camp 2020 Day 2E 阔力梯的树
    2017百越杯反序列化writeup
    大美西安writeup
    Thinkphp的SQL查询方式
    Thinkphp的CURD
    记一次拿webshell踩过的坑(如何用PHP编写一个不包含数字和字母的后门)
    ThinkPHP的输出和模型使用
    ThinkPHP的运行流程-2
  • 原文地址:https://www.cnblogs.com/winditsway/p/12759930.html
Copyright © 2020-2023  润新知