0819 SESAC(幼苗)第3期第7日目

11516 ワード


Django->ルーティング設定
将来サーバを開くには
  • プロジェクトフォルダ(manage.pyを含む)に移動します.
    manage.pyを含むフォルダはプロジェクトフォルダ
  • です.
    pythonファイルの実行時にpython 3を入力
    python3 manage.py runserver 0.0.0.0:(8000)
    ()勝手に位置を入れてはいけない数字もつながっている
    file zilla接続
    ホスト27.96.135.73
    ユーザー名root
    パスワードqa 2213886*
    ポート22
    root@yookeunbyul:~# ls
    b.html ssac-django
    root@yookeunbyul:~# cd ssac-django
    root@yookeunbyul:~/ssac-django# cd first_homepage/
    root@yookeunbyul:~/ssac-django/first_homepage# ls
    db.sqlite3 first_homepage manage.py member
    root@yookeunbyul:~/ssac-django/first_homepage# python3 manage.py runserver 0.0.0.0:8000
    プロジェクトと同じ名前のアプリケーションフォルダを使用して設定できます.
    root@yookeunbyul:~# ls
    b.html ssac-django
    root@yookeunbyul:~# cd ssac-django/
    root@yookeunbyul:~/ssac-django# ls
    first_homepage
    root@yookeunbyul:~/ssac-django# cd first_homepage/
    root@yookeunbyul:~/ssac-django/first_homepage# ls
    db.sqlite3 first_homepage manage.py member
    root@yookeunbyul:~/ssac-django/first_homepage# cd first_homepage/
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# ls
    asgi.py init.py pycache settings.py urls.py wsgi.py
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# vi settings.py
    配線設定→配線
    urls.pyは設定です.pyと同じ場所にあります.
    !!私たちだけのコース設定!!
    include->追加ファイルを許可!!
    yookenbullという名前のパスで入ると、メンバー内でurlsが使用されます.
    メンバーにはありませんがvi urlsです.pyを使用してurlsファイルを作成する
    プロジェクトフォルダのurls.py->最上位接続アドレス
    1234543534543534535/yookeunbyul/dddsdddf/dddddd
    yookenbullはトップレベルの接続アドレスです
    Path(「パス」、表示される内容)
    root@yookeunbyul:~# ls
    b.html ssac-django
    root@yookeunbyul:~# cd ssac-django
    root@yookeunbyul:~/ssac-django# ls
    first_homepage
    root@yookeunbyul:~/ssac-django# cd first_homepage/
    root@yookeunbyul:~/ssac-django/first_homepage# ls
    db.sqlite3 first_homepage manage.py member
    root@yookeunbyul:~/ssac-django/first_homepage# cd first_homepage/
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# ls
    asgi.py init.py pycache settings.py urls.py wsgi.py
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# vi urls.py
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# vi urls.py
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# vi urls.py
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# vi urls.py
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# cd ..
    root@yookeunbyul:~/ssac-django/first_homepage# ls
    db.sqlite3 first_homepage manage.py member
    root@yookeunbyul:~/ssac-django/first_homepage# cd memeber/
    -bash: cd: memeber/: No such file or directory
    root@yookeunbyul:~/ssac-django/first_homepage# cd member/
    root@yookeunbyul:~/ssac-django/first_homepage/member# ls
    admin.py init.py models.py tests.py
    apps.py migrations pycache views.py
    root@yookeunbyul:~/ssac-django/first_homepage/member# vi urls.py
    root@yookeunbyul:~/ssac-django/first_homepage/member# cd ..
    root@yookeunbyul:~/ssac-django/first_homepage# ls
    db.sqlite3 first_homepage manage.py member
    root@yookeunbyul:~/ssac-django/first_homepage# cd first_homepage/
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# ls
    asgi.py init.py pycache settings.py urls.py wsgi.py
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# vi urls.py
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# cd ..
    root@yookeunbyul:~/ssac-django/first_homepage# ls
    db.sqlite3 first_homepage manage.py member
    root@yookeunbyul:~/ssac-django/first_homepage# cd member/
    root@yookeunbyul:~/ssac-django/first_homepage/member# ls
    admin.py init.py models.py tests.py views.py
    apps.py migrations pycache urls.py
    root@yookeunbyul:~/ssac-django/first_homepage/member# vi urls.py
    root@yookeunbyul:~/ssac-django/first_homepage/member# cd ..
    root@yookeunbyul:~/ssac-django/first_homepage# ls
    db.sqlite3 first_homepage manage.py member
    root@yookeunbyul:~/ssac-django/first_homepage# cd first_homepage/
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# ls
    asgi.py init.py pycache settings.py urls.py wsgi.py
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# vi urls.py
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# ls
    asgi.py init.py pycache settings.py urls.py wsgi.py
    root@yookeunbyul:~/ssac-django/first_homepage/first_homepage# cd ..
    root@yookeunbyul:~/ssac-django/first_homepage# ls
    db.sqlite3 first_homepage manage.py member
    root@yookeunbyul:~/ssac-django/first_homepage# cd member/
    root@yookeunbyul:~/ssac-django/first_homepage/member# ls
    admin.py init.py models.py tests.py views.py
    apps.py migrations pycache urls.py
    root@yookeunbyul:~/ssac-django/first_homepage/member# vi urls.py
    urls.py
    from . import views
    -> . (すべての機能/自分の位置)
    path('ok', views.hello)
    ->viewsハローに行きます
    http://27.96.135.73:8000/yookeunbyul/ok
    views.py
    render->ファイルの作成
    from django.shortcuts import render
    #Create your views here.
    def hello( req ) :
    return render( req, 'a.html')
    views->バックエンド
    templates->フロントエンド
    root@yookeunbyul:~/ssac-django/first_homepage/member# mkdir templates
    root@yookeunbyul:~/ssac-django/first_homepage/member# ls
    admin.py init.py models.py templates urls.py
    apps.py migrations pycache tests.py views.py
    ヘッドのサブラベルとして入れればいいです.
    ラベルを閉じる必要はありません
    views.py
    from django.shortcuts import render
    #Create your views here.
    def hello( req ) :
    a = 5
    b = 8
    c = a + b
    return render( req, 'a.html', {'parameter1':c, 'parameter2':'육은별'})
    a. html
    hello
        <body>
                {{ parameter1 }}
    
                <div style="color:red;">
                        {{ parameter2 }}
                </div>
        </body>
  • 倉庫プロジェクト
  • の作成
  • ハンドヘルドアプリケーション
  • の作成
  • 配線
  • 指定したパスで接続する場合、動的ページ出力
  • root@yookeunbyul:~# ls
    b.html ssac-django
    root@yookeunbyul:~# mkdir my-django
    ディレクトリの作成
    root@yookeunbyul:~# ls
    b.html my-django ssac-django
    root@yookeunbyul:~# cd my-django/
    root@yookeunbyul:~/my-django# ;s
    -bash: syntax error near unexpected token `;'
    root@yookeunbyul:~/my-django# ls
    root@yookeunbyul:~/my-django# cd ..
    root@yookeunbyul:~# ls
    b.html my-django ssac-django
    root@yookeunbyul:~# cd ssac-django/
    root@yookeunbyul:~/ssac-django# ls
    first_homepage
    root@yookeunbyul:~/ssac-django# cd ..
    root@yookeunbyul:~# ls
    b.html my-django ssac-django
    root@yookeunbyul:~# cd my-django/
    root@yookeunbyul:~/my-django# django-admin startproject second_homepage
    プロジェクトの作成
    root@yookeunbyul:~/my-django# ls
    second_homepage
    root@yookeunbyul:~/my-django# cd second_homepage/
    プロジェクトフォルダへ
    root@yookeunbyul:~/my-django/second_homepage# ls
    manage.py second_homepage
    root@yookeunbyul:~/my-django/second_homepage# django-admin startapp member
    アプリケーションの作成
    root@yookeunbyul:~/my-django/second_homepage# ls
    manage.py member second_homepage
    root@yookeunbyul:~/my-django/second_homepage# cd second_homepage/
    (プロジェクトフォルダと同じ名前)アプリケーションフォルダへ
    root@yookeunbyul:~/my-django/second_homepage/second_homepage# ls
    asgi.py init.py settings.py urls.py wsgi.py
    root@yookeunbyul:~/my-django/second_homepage/second_homepage# vi settings.py
    ALLOWED HOSTS=["27.96.135.73"]を入力し、INSTALLED APPSで「メンバー」を作成
    root@yookeunbyul:~/my-django/second_homepage/second_homepage# ls
    asgi.py init.py settings.py urls.py wsgi.py
    root@yookeunbyul:~/my-django/second_homepage/second_homepage# vi urls.py
    urls.pyの最上位接続アドレスを入力
    from django.contrib import admin
    from django.urls import path, include
    urlpatterns = [
    path('admin/', admin.site.urls),
    path('yookbyul/', include('member.urls'))
    ]
    メンバーへのURL
    root@yookeunbyul:~/my-django/second_homepage/second_homepage# ls
    asgi.py init.py settings.py urls.py wsgi.py
    root@yookeunbyul:~/my-django/second_homepage/second_homepage# cd ..
    root@yookeunbyul:~/my-django/second_homepage# ls
    manage.py member second_homepage
    root@yookeunbyul:~/my-django/second_homepage# cd member/
    アプリケーションへのアクセス
    root@yookeunbyul:~/my-django/second_homepage/member# ls
    admin.py apps.py init.py migrations models.py tests.py views.py
    root@yookeunbyul:~/my-django/second_homepage/member# vi urls.py
    from django.urls import path
    from . import views
    urlpatterns = [
    path('no', views.hello)
    ]
    2番目のパスを作成するビューhelloに移動します
    root@yookeunbyul:~/my-django/second_homepage/member# vi views.py
    from django.shortcuts import render
    #Create your views here.
    def hello(req) :
    return render(req, 'c.html')
    helloはc.htmlです
    root@yookeunbyul:~/my-django/second_homepage/member# ls
    admin.py init.py models.py urls.py
    apps.py migrations tests.py views.py
    root@yookeunbyul:~/my-django/second_homepage/member# mkdir templates
    メンバーにtemplatesというディレクトリを作成する
    root@yookeunbyul:~/my-django/second_homepage/member# ls
    admin.py init.py models.py tests.py views.py
    apps.py migrations templates urls.py
    root@yookeunbyul:~/my-django/second_homepage/member# cd templates/
    テンプレートに入ります.
    root@yookeunbyul:~/my-django/second_homepage/member/templates# ls
    root@yookeunbyul:~/my-django/second_homepage/member/templates# vi c.html
    c.htmlの作成
    secondhomepage
        <body>
                hello
        </body>
    root@yookeunbyul:~/my-django/second_homepage/member/templates#
    書き終わったら倉庫サーバーを開きます.
    http://27.96.135.73:8000/yookbyul/noこのリンクに入ると成功!