前言

虽然现在有点晚了,但是想了一下,qexo的新建页面还是挺简单的,所以从床上爬起来把这篇文章给写(水🤪)了。

预览效果

效果如下:
侧边栏按钮
页面内容

创建html模板

新建 templates\home\test.html 文件,添加内容如下:

1
2
3
4
5
6
7
8
9
10
11
{% extends 'layouts/base.html' %}

{% block content %}
<p>hello world!</p>
<p>{{ hi }}</p>
{% include "includes/footer.html" %}
{% endblock content %}

<!-- Specific JS goes HERE -->
{% block javascripts %}
{% endblock javascripts %}

添加侧边栏的页面入口按钮

找到 templates\includes\sidenav.html 文件,修改内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    <li class="nav-item">
<a class="nav-link {% if 'talks' in segment %} active {% endif %}" href="/talks.html">
<i class="ni ni-chat-round text-purple"></i>
<span class="nav-link-text">说说</span>
</a>
</li>
+ <li class="nav-item">
+ <a class="nav-link {% if 'test' in segment %} active {% endif %}" href="/test.html">
+ <i class="ni ni-chat-round text-purple"></i>
+ <span class="nav-link-text">test</span>
+ </a>
+ </li>
{% if request.user.is_staff %}
<li class="nav-item">
<a class="nav-link {% if 'custom' in segment %} active {% endif %}" href="/custom.html">
<i class="ni ni-archive-2 text-primary"></i>
<span class="nav-link-text">自定</span>
</a>
</li>
{% endif %}

添加模板渲染处理

找到 hexoweb\views.py 文件,添加内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
elif "userscripts" in load_template:
if not request.user.is_staff:
logging.info(f"子用户{request.user.username}尝试访问{request.path}被拒绝")
return page_403(request, "您没有权限访问此页面")
try:
search = request.GET.get("s")
scripts = requests.get("https://raw.githubusercontent.com/Qexo/Scripts/main/index.json").json()
context["posts"] = list()
for script in scripts:
if (not search) or (search.upper() in script["name"].upper()) or (search.upper() in script["author"].upper()):
context["posts"].append(script)
if search:
context["search"] = search
context["post_number"] = len(context["posts"])
context["page_number"] = ceil(context["post_number"] / 15)
context["all_posts"] = json.dumps(context["posts"])
except Exception as e:
logging.error("获取错误: " + repr(e))
context["error"] = repr(e)
+elif "test" in load_template:
+ context["hi"] = "hi"

save_setting("LAST_LOGIN", str(int(time())))
html_template = loader.get_template('home/' + load_template)
return HttpResponse(html_template.render(context, request))

Qexo四连

在cmd命令行中输入如下命令运行部署Qexo项目:

1
2
3
4
E:\Qexo> pip3 install -r requirements.txt
E:\Qexo> python3 manage.py makemigrations
E:\Qexo> python3 manage.py migrate
E:\Qexo> python3 manage.py runserver --noreload

访问 http://127.0.0.1:8000/ 查看页面效果。