Beracles commited on
Commit
57f4af2
·
1 Parent(s): 605d720
.gitignore ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
Dockerfile ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.10.5
5
+
6
+ # Set up a new user named "user" with user ID 1000
7
+ RUN useradd -m -u 1000 user
8
+
9
+ # Switch to the "user" user
10
+ USER user
11
+
12
+ # Set home to the user's home directory
13
+ ENV HOME=/home/user \
14
+ PATH=/home/user/.local/bin:$PATH
15
+
16
+ # Set the working directory to the user's home directory
17
+ WORKDIR $HOME/code/myweb
18
+
19
+ COPY ./requirements.txt /code/requirements.txt
20
+
21
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
22
+
23
+ COPY . .
24
+
25
+ # port where the Django app runs
26
+ EXPOSE 7860
27
+
28
+
29
+ # start server
30
+ CMD python manage.py runserver
31
+
32
+
33
+ # if using fastapi framework
34
+ # CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
demo.html ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <form action="/" method="post">
3
+ <!-- 文本输入框 -->
4
+ <label for="name">用户名:</label>
5
+ <input type="text" id="name" name="name" required>
6
+
7
+ <br>
8
+
9
+ <!-- 密码输入框 -->
10
+ <label for="password">密码:</label>
11
+ <input type="password" id="password" name="password" required>
12
+
13
+ <br>
14
+
15
+ <!-- 单选按钮 -->
16
+ <label>性别:</label>
17
+ <input type="radio" id="male" name="gender" value="male" checked>
18
+ <label for="male">男</label>
19
+ <input type="radio" id="female" name="gender" value="female">
20
+ <label for="female">女</label>
21
+
22
+ <br>
23
+
24
+ <!-- 复选框 -->
25
+ <input type="checkbox" id="subscribe" name="subscribe" checked>
26
+ <label for="subscribe">订阅推送信息</label>
27
+
28
+ <br>
29
+
30
+ <!-- 下拉列表 -->
31
+ <label for="country">国家:</label>
32
+ <select id="country" name="country">
33
+ <option value="cn">CN</option>
34
+ <option value="usa">USA</option>
35
+ <option value="uk">UK</option>
36
+ </select>
37
+
38
+ <br>
39
+
40
+ <!-- 提交按钮 -->
41
+ <input type="submit" value="提交">
42
+ </form>
myweb/firstapp/__init__.py ADDED
File without changes
myweb/firstapp/admin.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.contrib import admin
2
+
3
+ # Register your models here.
myweb/firstapp/apps.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class FirstappConfig(AppConfig):
5
+ default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'firstapp'
myweb/firstapp/migrations/__init__.py ADDED
File without changes
myweb/firstapp/models.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.db import models
2
+
3
+ # Create your models here.
myweb/firstapp/tests.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.test import TestCase
2
+
3
+ # Create your tests here.
myweb/firstapp/views.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.shortcuts import render
2
+ from django.http import HttpResponse
3
+
4
+
5
+ def index(request):
6
+ return HttpResponse("This is the first application of myweb.")
7
+
8
+ def root(request):
9
+ render(request,)
10
+ return HttpResponse("Welcome to myweb!")
myweb/manage.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """Django's command-line utility for administrative tasks."""
3
+ import os
4
+ import sys
5
+
6
+
7
+ def main():
8
+ """Run administrative tasks."""
9
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myweb.settings')
10
+ try:
11
+ from django.core.management import execute_from_command_line
12
+ except ImportError as exc:
13
+ raise ImportError(
14
+ "Couldn't import Django. Are you sure it's installed and "
15
+ "available on your PYTHONPATH environment variable? Did you "
16
+ "forget to activate a virtual environment?"
17
+ ) from exc
18
+ execute_from_command_line(sys.argv)
19
+
20
+
21
+ if __name__ == '__main__':
22
+ main()
myweb/myweb/__init__.py ADDED
File without changes
myweb/myweb/asgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ASGI config for myweb project.
3
+
4
+ It exposes the ASGI callable as a module-level variable named ``application``.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
8
+ """
9
+
10
+ import os
11
+
12
+ from django.core.asgi import get_asgi_application
13
+
14
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myweb.settings')
15
+
16
+ application = get_asgi_application()
myweb/myweb/settings.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Django settings for myweb project.
3
+
4
+ Generated by 'django-admin startproject' using Django 5.0.3.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/5.0/topics/settings/
8
+
9
+ For the full list of settings and their values, see
10
+ https://docs.djangoproject.com/en/5.0/ref/settings/
11
+ """
12
+
13
+ import os
14
+ from pathlib import Path
15
+
16
+ # Build paths inside the project like this: BASE_DIR / 'subdir'.
17
+ BASE_DIR = Path(__file__).resolve().parent.parent
18
+
19
+
20
+ # Quick-start development settings - unsuitable for production
21
+ # See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
22
+
23
+ # SECURITY WARNING: keep the secret key used in production secret!
24
+ SECRET_KEY = 'django-insecure-evpl&c@ar07^wl0v$4z_+_ey2(ylj-q@o&rx*9f+k^5wvhu&kf'
25
+
26
+ # SECURITY WARNING: don't run with debug turned on in production!
27
+ DEBUG = True
28
+
29
+ ALLOWED_HOSTS = ["*"]
30
+
31
+
32
+ # Application definition
33
+
34
+ INSTALLED_APPS = [
35
+ 'django.contrib.admin',
36
+ 'django.contrib.auth',
37
+ 'django.contrib.contenttypes',
38
+ 'django.contrib.sessions',
39
+ 'django.contrib.messages',
40
+ 'django.contrib.staticfiles',
41
+ "firstapp",
42
+ ]
43
+
44
+ MIDDLEWARE = [
45
+ 'django.middleware.security.SecurityMiddleware',
46
+ 'django.contrib.sessions.middleware.SessionMiddleware',
47
+ 'django.middleware.common.CommonMiddleware',
48
+ 'django.middleware.csrf.CsrfViewMiddleware',
49
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
50
+ 'django.contrib.messages.middleware.MessageMiddleware',
51
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
52
+ ]
53
+
54
+ ROOT_URLCONF = 'myweb.urls'
55
+
56
+ TEMPLATES = [
57
+ {
58
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
59
+ 'DIRS': [os.path.join(BASE_DIR, 'templates')],
60
+ 'APP_DIRS': True,
61
+ 'OPTIONS': {
62
+ 'context_processors': [
63
+ 'django.template.context_processors.debug',
64
+ 'django.template.context_processors.request',
65
+ 'django.contrib.auth.context_processors.auth',
66
+ 'django.contrib.messages.context_processors.messages',
67
+ ],
68
+ },
69
+ },
70
+ ]
71
+
72
+ WSGI_APPLICATION = 'myweb.wsgi.application'
73
+
74
+
75
+ # Database
76
+ # https://docs.djangoproject.com/en/5.0/ref/settings/#databases
77
+
78
+ DATABASES = {
79
+ 'default': {
80
+ 'ENGINE': 'django.db.backends.sqlite3',
81
+ 'NAME': BASE_DIR / 'db.sqlite3',
82
+ }
83
+ }
84
+
85
+
86
+ # Password validation
87
+ # https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
88
+
89
+ AUTH_PASSWORD_VALIDATORS = [
90
+ {
91
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
92
+ },
93
+ {
94
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
95
+ },
96
+ {
97
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
98
+ },
99
+ {
100
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
101
+ },
102
+ ]
103
+
104
+
105
+ # Internationalization
106
+ # https://docs.djangoproject.com/en/5.0/topics/i18n/
107
+
108
+ LANGUAGE_CODE = 'en-us'
109
+
110
+ TIME_ZONE = 'UTC'
111
+
112
+ USE_I18N = True
113
+
114
+ USE_TZ = True
115
+
116
+
117
+ # Static files (CSS, JavaScript, Images)
118
+ # https://docs.djangoproject.com/en/5.0/howto/static-files/
119
+
120
+ STATIC_URL = 'static/'
121
+
122
+ # Default primary key field type
123
+ # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
124
+
125
+ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
myweb/myweb/urls.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ URL configuration for myweb project.
3
+
4
+ The `urlpatterns` list routes URLs to views. For more information please see:
5
+ https://docs.djangoproject.com/en/5.0/topics/http/urls/
6
+ Examples:
7
+ Function views
8
+ 1. Add an import: from my_app import views
9
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
10
+ Class-based views
11
+ 1. Add an import: from other_app.views import Home
12
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13
+ Including another URLconf
14
+ 1. Import the include() function: from django.urls import include, path
15
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16
+ """
17
+ from django.contrib import admin
18
+ from django.urls import path
19
+ from firstapp import views
20
+
21
+ urlpatterns = [
22
+ path('admin/', admin.site.urls),
23
+ path('firstapp/',views.index),
24
+ path('',views.root)
25
+ ]
myweb/myweb/wsgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ WSGI config for myweb project.
3
+
4
+ It exposes the WSGI callable as a module-level variable named ``application``.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
8
+ """
9
+
10
+ import os
11
+
12
+ from django.core.wsgi import get_wsgi_application
13
+
14
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myweb.settings')
15
+
16
+ application = get_wsgi_application()
myweb/static/index.css ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ input{
2
+ font-size:large;
3
+ width: 250px;
4
+ }
5
+ button{
6
+ font-size:large;
7
+ }
8
+ select{
9
+ font-size:large;
10
+ width: 250px;
11
+ text-align: center;
12
+ }
13
+ pre{
14
+ font-size: large;
15
+ border: 2px solid black;
16
+ border-radius: 3px;
17
+ background-color: silver;
18
+ height: 180px;
19
+ width: 500px;
20
+ }
21
+ a{
22
+ font-size: larger;
23
+ }
myweb/static/index.html ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <body>
5
+ <header>
6
+ <title>AI Patcher</title>
7
+ <h1 style="text-align: center;">AI Patcher</h1>
8
+ </header>
9
+ <div style="text-align: center;">
10
+ <a href="http://127.0.0.1:8000/watermelon/">Watermelon</a>
11
+
12
+ </div>
13
+ </body>
14
+
15
+ </html>
myweb/static/watermelon/help/index.html ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <title>AI Patcher</title>
6
+ <link rel="stylesheet" type="text/css" href="../../index.css">
7
+ </head>
8
+
9
+ <body>
10
+ <h1 style="text-align: center;">help</h1>
11
+ <form action="" onsubmit="sendMessage(event)">
12
+ <div style="display: flex;flex-direction: column;align-items: center;">
13
+ <p>Command:
14
+ <input type="text" id="command" name="command" required />
15
+ </p>
16
+ <button>Send</button>
17
+ </div>
18
+ </form>
19
+ <div style="display: flex;flex-direction: column;align-items: center;">
20
+
21
+ <div>
22
+ <p>Response:</p>
23
+ <pre id="messages"></pre>
24
+ </div>
25
+ </div>
26
+ <script src="index.js"></script>
27
+ </body>
28
+
29
+ </html>
myweb/static/watermelon/help/index.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // help
2
+ var ws = new WebSocket("ws://localhost:8000/watermelon/ws");
3
+ ws.onmessage = function (event) {
4
+ var messages = document.getElementById('messages')
5
+ messages.innerText = event.data
6
+ };
7
+ function sendMessage(event) {
8
+ var input = document.getElementById("command")
9
+
10
+ var myobj = {
11
+ url: "help",
12
+ data: {
13
+ command: input.value
14
+ }
15
+ }
16
+ ws.send(JSON.stringify(myobj))
17
+ event.preventDefault()
18
+ }
myweb/static/watermelon/index.html ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <title>AI Patcher</title>
6
+ <h1 style="text-align: center;">AI Patcher for Watermelon</h1>
7
+ <link rel="stylesheet" type="text/css" href="../index.css">
8
+ </head>
9
+
10
+ <body>
11
+ <div style="display: flex;flex-direction: column;align-items: center;">
12
+ <div style="display:flex;flex-direction: column;">
13
+ <a href="http://127.0.0.1:8000/watermelon/help/index.html">help</a>
14
+ <a href="http://127.0.0.1:8000/watermelon/reset_game/index.html">reset_game</a>
15
+ <a href="http://127.0.0.1:8000/watermelon/set_number_of_sth/index.html">set_number_of_sth</a>
16
+ </div>
17
+ </div>
18
+ <script src="index.js"></script>
19
+ </body>
20
+
21
+ </html>
myweb/static/watermelon/index.js ADDED
File without changes
myweb/templates/base.html ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- 载入静态文件-->
2
+ {% load static %}
3
+
4
+ <!DOCTYPE html>
5
+ <!-- 网站主语言 -->
6
+ <html lang="zh-cn">
7
+ <head>
8
+ <!-- 网站采用的字符编码 -->
9
+ <meta charset="utf-8">
10
+ <!-- 预留网站标题的位置 -->
11
+ <title>{% block title %}{% endblock %}</title>
12
+ <!-- 引入bootstrap的css文件 -->
13
+ <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
14
+ <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
15
+ <!-- 引入layer.js -->
16
+ <link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
17
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">
18
+ </head>
19
+
20
+ <body>
21
+ <!-- 引入导航栏 -->
22
+ {% include 'header.html' %}
23
+ <!-- 预留具体页面的位置 -->
24
+ {% block content %}{% endblock content %}
25
+ <!-- 引入注脚 -->
26
+ {% include 'footer.html' %}
27
+ <!-- bootstrap.js 依赖 jquery.js 和popper.js,因此在这里引入 -->
28
+ <script src="{% static 'jquery/jquery-3.6.0.js' %}"></script>
29
+
30
+ <!--
31
+ popper.js 采用 cdn 远程引入,意思是你不需要把它下载到本地。
32
+ 在实际的开发中推荐静态文件尽量都使用 cdn 的形式。
33
+ 教程采用本地引入是为了让读者了解静态文件本地部署的流程。
34
+ -->
35
+ <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1-lts/dist/umd/popper.min.js"></script>
36
+
37
+ <!-- 引入bootstrap的js文件 -->
38
+ <script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
39
+ </body>
40
+
41
+ </html>
myweb/templates/footer.html ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {% load static %}
2
+ <!-- Footer -->
3
+ <div>
4
+ <br><br><br>
5
+ </div>
6
+ <footer class="py-3 bg-dark fixed-bottom">
7
+ <div class="container">
8
+ <p class="m-0 text-center text-white">Copyright &copy; MyWeb 2021</p>
9
+ </div>
10
+ </footer>
myweb/templates/header.html ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- 定义导航栏 -->
2
+ <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
3
+ <div class="container">
4
+ <!-- 导航栏商标 -->
5
+ <a class="navbar-brand" href="#">MyWeb</a>
6
+ <!-- 导航入口 -->
7
+ <div>
8
+ <ul class="navbar-nav">
9
+ <li class="nav-item">
10
+ <a class="nav-link" href="{% url 'article:article_create' %}">创作</a>
11
+ </li>
12
+ <li class="nav-item">
13
+ <a class="nav-link" href="{% url 'article:article_list' %}">首页</a>
14
+ </li>
15
+ <!-- Django的 if 模板语句 -->
16
+ {% if user.is_authenticated %}
17
+ <!-- 如果用户已经登录,则显示用户名下拉框 -->
18
+ <li class="nav-item dropdown">
19
+ <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
20
+ {{ user.username }}
21
+ </a>
22
+ <div class="dropdown-menu" aria-labelledby="navbarDropdown">
23
+ <a class="dropdown-item" href='{% url "userprofile:logout" %}'>退出登录</a>
24
+ </div>
25
+ </li>
26
+ <!-- 如果用户未登录,则显示 “登录” -->
27
+ {% else %}
28
+ <li class="nav-item">
29
+ <a class="nav-link" href="{% url 'userprofile:login' %}">登录</a>
30
+ </li>
31
+ <!-- if 语句在这里结束 -->
32
+ {% endif %}
33
+ </ul>
34
+ </div>
35
+ </div>
36
+ </nav>
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ django