Spaces:
Running
Running
Beracles
commited on
Commit
·
6efe012
1
Parent(s):
8d876c0
update
Browse files- Dockerfile +0 -4
- myweb/firstapp/models.py +0 -9
- myweb/firstapp/views.py +0 -29
- myweb/myweb/settings.py +1 -1
- myweb/myweb/urls.py +3 -4
- myweb/static/watermelon/help/index.js +0 -18
- myweb/static/watermelon/index.js +0 -0
- myweb/templates/base.html +0 -41
- myweb/templates/footer.html +0 -10
- myweb/templates/header.html +0 -36
- myweb/{static → templates}/index.html +1 -1
- myweb/{static → templates}/watermelon/help/index.html +0 -0
- myweb/{static → templates}/watermelon/index.html +1 -3
- myweb/{firstapp → watermelon}/__init__.py +0 -0
- myweb/{firstapp → watermelon}/admin.py +0 -0
- myweb/{firstapp → watermelon}/apps.py +2 -2
- myweb/{firstapp → watermelon}/migrations/__init__.py +0 -0
- myweb/watermelon/models.py +3 -0
- myweb/{firstapp → watermelon}/tests.py +0 -0
- myweb/watermelon/urls.py +9 -0
- myweb/watermelon/views.py +14 -0
Dockerfile
CHANGED
|
@@ -28,7 +28,3 @@ EXPOSE 7860
|
|
| 28 |
|
| 29 |
# start server
|
| 30 |
CMD python myweb/manage.py runserver 0.0.0.0:7860
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
# if using fastapi framework
|
| 34 |
-
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 28 |
|
| 29 |
# start server
|
| 30 |
CMD python myweb/manage.py runserver 0.0.0.0:7860
|
|
|
|
|
|
|
|
|
|
|
|
myweb/firstapp/models.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
from django.db import models
|
| 2 |
-
|
| 3 |
-
# Create your models here.
|
| 4 |
-
class Message:
|
| 5 |
-
def __init__(self, id, text, sender, recipient):
|
| 6 |
-
self.id = id
|
| 7 |
-
self.text = text
|
| 8 |
-
self.sender = sender
|
| 9 |
-
self.recipient = recipient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
myweb/firstapp/views.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
from django.shortcuts import render
|
| 2 |
-
from django.http import HttpResponse
|
| 3 |
-
from rest_framework.decorators import api_view
|
| 4 |
-
from rest_framework.response import Response
|
| 5 |
-
from .models import Message
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def index(request):
|
| 9 |
-
return HttpResponse("This is the first application of myweb.")
|
| 10 |
-
|
| 11 |
-
def root(request):
|
| 12 |
-
return HttpResponse("Welcome to myweb!")
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
@api_view(['GET'])
|
| 16 |
-
def messages_list(request):
|
| 17 |
-
messages = [
|
| 18 |
-
Message(1, 'Hello!', 'John', 'Alice'),
|
| 19 |
-
Message(2, 'How are you?', 'Alice', 'John'),
|
| 20 |
-
]
|
| 21 |
-
response_data = []
|
| 22 |
-
for message in messages:
|
| 23 |
-
response_data.append({
|
| 24 |
-
'id': message.id,
|
| 25 |
-
'text': message.text,
|
| 26 |
-
'sender': message.sender,
|
| 27 |
-
'recipient': message.recipient,
|
| 28 |
-
})
|
| 29 |
-
return Response(response_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
myweb/myweb/settings.py
CHANGED
|
@@ -38,7 +38,7 @@ INSTALLED_APPS = [
|
|
| 38 |
'django.contrib.sessions',
|
| 39 |
'django.contrib.messages',
|
| 40 |
'django.contrib.staticfiles',
|
| 41 |
-
"
|
| 42 |
]
|
| 43 |
|
| 44 |
MIDDLEWARE = [
|
|
|
|
| 38 |
'django.contrib.sessions',
|
| 39 |
'django.contrib.messages',
|
| 40 |
'django.contrib.staticfiles',
|
| 41 |
+
"watermelon",
|
| 42 |
]
|
| 43 |
|
| 44 |
MIDDLEWARE = [
|
myweb/myweb/urls.py
CHANGED
|
@@ -15,12 +15,11 @@ Including another URLconf
|
|
| 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
|
| 20 |
|
| 21 |
urlpatterns = [
|
| 22 |
path('admin/', admin.site.urls),
|
| 23 |
-
path('
|
| 24 |
path('',views.root),
|
| 25 |
-
path('messagelist/',views.messages_list)
|
| 26 |
]
|
|
|
|
| 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,include
|
| 19 |
+
from watermelon import views
|
| 20 |
|
| 21 |
urlpatterns = [
|
| 22 |
path('admin/', admin.site.urls),
|
| 23 |
+
path('watermelon/',include("watermelon.urls",namespace="watermelon")),
|
| 24 |
path('',views.root),
|
|
|
|
| 25 |
]
|
myweb/static/watermelon/help/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
| 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.js
DELETED
|
File without changes
|
myweb/templates/base.html
DELETED
|
@@ -1,41 +0,0 @@
|
|
| 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
DELETED
|
@@ -1,10 +0,0 @@
|
|
| 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 © MyWeb 2021</p>
|
| 9 |
-
</div>
|
| 10 |
-
</footer>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
myweb/templates/header.html
DELETED
|
@@ -1,36 +0,0 @@
|
|
| 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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
myweb/{static → templates}/index.html
RENAMED
|
@@ -7,7 +7,7 @@
|
|
| 7 |
<h1 style="text-align: center;">AI Patcher</h1>
|
| 8 |
</header>
|
| 9 |
<div style="text-align: center;">
|
| 10 |
-
<a href="
|
| 11 |
|
| 12 |
</div>
|
| 13 |
</body>
|
|
|
|
| 7 |
<h1 style="text-align: center;">AI Patcher</h1>
|
| 8 |
</header>
|
| 9 |
<div style="text-align: center;">
|
| 10 |
+
<a href="watermelon">Watermelon</a>
|
| 11 |
|
| 12 |
</div>
|
| 13 |
</body>
|
myweb/{static → templates}/watermelon/help/index.html
RENAMED
|
File without changes
|
myweb/{static → templates}/watermelon/index.html
RENAMED
|
@@ -10,9 +10,7 @@
|
|
| 10 |
<body>
|
| 11 |
<div style="display: flex;flex-direction: column;align-items: center;">
|
| 12 |
<div style="display:flex;flex-direction: column;">
|
| 13 |
-
<a href="
|
| 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>
|
|
|
|
| 10 |
<body>
|
| 11 |
<div style="display: flex;flex-direction: column;align-items: center;">
|
| 12 |
<div style="display:flex;flex-direction: column;">
|
| 13 |
+
<a href="help">help</a>
|
|
|
|
|
|
|
| 14 |
</div>
|
| 15 |
</div>
|
| 16 |
<script src="index.js"></script>
|
myweb/{firstapp → watermelon}/__init__.py
RENAMED
|
File without changes
|
myweb/{firstapp → watermelon}/admin.py
RENAMED
|
File without changes
|
myweb/{firstapp → watermelon}/apps.py
RENAMED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from django.apps import AppConfig
|
| 2 |
|
| 3 |
|
| 4 |
-
class
|
| 5 |
default_auto_field = 'django.db.models.BigAutoField'
|
| 6 |
-
name = '
|
|
|
|
| 1 |
from django.apps import AppConfig
|
| 2 |
|
| 3 |
|
| 4 |
+
class WatermelonConfig(AppConfig):
|
| 5 |
default_auto_field = 'django.db.models.BigAutoField'
|
| 6 |
+
name = 'watermelon'
|
myweb/{firstapp → watermelon}/migrations/__init__.py
RENAMED
|
File without changes
|
myweb/watermelon/models.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.db import models
|
| 2 |
+
|
| 3 |
+
# Create your models here.
|
myweb/{firstapp → watermelon}/tests.py
RENAMED
|
File without changes
|
myweb/watermelon/urls.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.urls import path
|
| 2 |
+
from . import views
|
| 3 |
+
|
| 4 |
+
app_name = 'watermelon'
|
| 5 |
+
|
| 6 |
+
urlpatterns = [
|
| 7 |
+
path("", views.index),
|
| 8 |
+
path("help/",views.help)
|
| 9 |
+
]
|
myweb/watermelon/views.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.shortcuts import render
|
| 2 |
+
|
| 3 |
+
# Create your views here.
|
| 4 |
+
def root(request):
|
| 5 |
+
response=render(request,"index.html")
|
| 6 |
+
return response
|
| 7 |
+
|
| 8 |
+
def index(request):
|
| 9 |
+
response=render(request,"watermelon/index.html")
|
| 10 |
+
return response
|
| 11 |
+
|
| 12 |
+
def help(request):
|
| 13 |
+
response=render(request,"watermelon/help/index.html")
|
| 14 |
+
return response
|