首页完成後 让使用者可以进入使用者个人文件页
列出属於此使用者的文件
我已经先用测试网页塞了测试资料给此使用者
doc_info/views.py 资料库内筛选使用者id然後传送给前端
使用修饰器来验证是否有登入,如果没有的话会导到登入页面
网址会变成http://127.0.0.1:8000/accounts/login/?next=/doc/user/list/
next表示登入完之後会导到哪一页、登入完成後会导回到此页
from django.contrib.auth.decorators import login_required
@login_required
def doc_user_list(request):
user = request.user
Doc_warehouse = doc_warehouse.objects.filter(user_id=user.id)
return render(request, 'doc/user_list.html', {'Doc_warehouse': Doc_warehouse})
doc_info/urls.py 增加转址到使用者个人文件页的路径
urlpatterns = [
path('doc/user/list/', views.doc_user_list, name='user_list'),
]
templates/user_list.html 增加使用者文件页
首先将各个按钮加入(首页、使用者个人资料页、登入登出页、创建文件页)
创建文件页我先用一个空的html让程序不会出现转址错误
然後用表格+回圈的方式列出使用者文件
删除按钮的部分也先用空的html替代
{% block content %}
<a href="{% url 'doc_info:main' %}">Main page</a> |
<a href="{% url 'auth_info:profile' %}">My Profile</a> |
<a href="{% url 'account_logout' %}">Logout</a>
<p>Welcome {{ user.first_name }} {{ user.last_name }}</p>
<a href="{% url 'doc_info:create' %}">Create document</a>
<p></p>
<table border = "1">
<thead>
<tr>
<th >Create date: </th>
<th>Last modified date:</th>
<th>Author</th>
<th>Title</th>
<th>Remark</th>
<th>Link</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{% for doc in Doc_warehouse %}
<tr>
<td>{{ doc.create_date }}</td>
<td>{{ doc.last_mod_date }}</td>
<td>{{ doc.user }}</td>
<td>{{ doc.title }}</td>
<td>{{ doc.remark }}</td>
<td>{{ doc.link }}</td>
<td><a href="{% url 'doc_info:delete' doc_id=doc.id %}" onclick="return confirm('Are you sure you want to delete this?')">Delete</a></td>
{% endfor %}
</tr>
</tbody>
</table>
{% endblock %}
简略的使用者个人文件页如下
>>: DAY18 - [JS] 合体ToDoList + 番茄钟
一、前言 先前有提到,我在转职後、进到现职公司前,其实还有录取过另外一份PHP後端工程师之职缺,...
1.JS是什麽? Java Script 是一种运行在客户端的脚本语言 (script就是脚本的意思...
今天邀请到来自新化高中的 Colten 来分享他在高中竞程这条路上的种种历程。本次访谈有公开浏览,欢...
题型为多选题的题目 可以用gogole form 中的「核取方块」出题 特徵为在预览模式中 选项前为...
这个得上一篇:https://ithelp.ithome.com.tw/articles/10259...