制作文件系统首页
先将使用者的个人资料页做好
回到docsystem_5
django-admin startapp doc_info
创建新的app
doc_info/models.py 先建立好资料库的栏位
from django.db import models
from django.contrib.auth.models import User
from allauth.account.models import EmailAddress
class doc_warehouse(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='doc_warehouse')
create_date = models.DateTimeField(auto_now_add=True)
last_mod_date = models.DateTimeField(auto_now=True)
title = models.CharField(max_length=128, blank=True)
remark = models.CharField(max_length=128, blank=True)
status = models.IntegerField(default=1, null=True, blank=True)
link = models.CharField(max_length=128, blank=True)
doc_info/views.py 设定逻辑
把所有在文件仓库的资料传给templates
from django.shortcuts import render, get_object_or_404
from auth_info.models import UserProfile
from .models import doc_warehouse
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.contrib.auth.decorators import login_required
def doc_main(request):
user = request.user
Doc_warehouse = doc_warehouse.objects.all()
return render(request, 'doc/main.html', {'Doc_warehouse': Doc_warehouse})
tmplates/doc/main.html 设定首页长相
首先先列出使用者个人资料页、个人文件页、登入登出按钮
然後直接列出所有档案
{% block content %}
<a href="{% url 'auth_info:profile' %}">My Profile</a> |
<a href="{% url 'doc_info:user_list' %}">My Documents</a> |
{% if user.is_authenticated %}
<a href="{% url 'account_logout' %}">Logout</a>
{% else %}
<a href="{% url 'account_login' %}">Login</a>
{% endif %}
<p>Welcome {{ user.first_name }} {{ user.last_name }}</p>
<h2>Document List</h2>
<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>
</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>
{% endfor %}
</tr>
</tbody>
</table>
{% endblock %}
doc_info/urls.py 设定转址规则
from django.urls import path
from . import views
app_name = "doc_info"
urlpatterns = [
path('doc/main/', views.doc_main, name='main'),
]
docsystem_5/setting.py 加入app
INSTALLED_APPS = [
'doc_info',
]
记得要执行以下创建table
python manage.py makemigrations #告诉django依据model跟installed_app要该栋那些table
python manage.py migrate #执行以上的变动
python manage.py runserver #执行server
http://127.0.0.1:8000/doc/main/ 展示如下图
>>: Kneron - Kneron Toolchain 转档操作参考笔记
说明 关於 FHIR 服务器 FHIR 有非常多服务器端的实作,这边使用的是 HAPI FHIR。这...
嗨大家!今天在串 Notion SDK 时因为想要实作 pagination (分页) 的关系,才发...
现今常常会在购物网站中看到顾客点选产品时,网页会依据顾客的操作自动列出清单,或是看到一些使用者在输入...
是说TS针对型别的类型也太讲究,写好多天还没写完(其实是我30篇不够XDD),哈哈不罗嗦, 今天继...
Aloha!我是少女人妻 Uerica!我家狗狗每天六点都会叫我起床,但除非自己很早睡,不然六点起床...