pixabay https://cdn.pixabay.com/photo/2019/05/14/17/07/web-development-4202909_1280.png [上期](https://peakd.com/hive-105017/@june0620/python-9-django-2-steem-python-steem)简单的尝试了下把我的STEEM信息投放到网页,今天把我的POSTS放到网页上吧。(#边学边写真难) ##### 添加 URL 首先在blog目录下的 `urls.py` 添加相关url。用`slug`来判断并读取`Views.py`的posts类,用.as_view()来显示ListView。 ``` from django.urls import path from .views import main_view, posts urlpatterns = [ path('', main_view, name='my_home'), path('@<slug:account>/', posts.as_view(), name='posts'), ] ``` ![image.png](https://files.peakd.com/file/peakd-hive/june0620/Ohk3u4QJ-image.png) ##### 添加类到`Views.py` 因上面命名了post,所以在 `Views.py`文件加上相应的类,这个类继承django的ListView。 重定义get函数,这里我们用到 `Services.py`里的 blog 函数。 ``` from .services import my_data, blogs class posts(ListView): template_name = 'posts.html' context_object_name = 'all_posts' def get(self, request, *args, **kwargs): self.queryset = blogs(kwargs['account']) return super().get(request, *args, **kwargs) ``` ![image.png](https://files.peakd.com/file/peakd-hive/june0620/3wcNGQdX-image.png) ##### 获取 POST 列表 用 steem-python 库调用某人的post列表,填入到 `Services.py`。 ``` from steem import Steem def blogs(account=str): s = Steem() blogs = s.get_blog(account, entry_id=0, limit=50) return blogs ``` ![image.png](https://files.peakd.com/file/peakd-hive/june0620/VXI3eDKg-image.png) ##### 创建模板 该创建网页模板了,创建一个叫 `templates` 的文件夹到 `blog` 文件夹同级别下,并在之下创建一个 `posts.html`网页文件。 ``` $ mkdir templates $ touch templates/home.html ``` 之后在html文件写入如下: ``` <h1>My Steem Blog</h1> <ul> {% for post in all_posts %} <li><a href="https://www.steemit.com/@{{post.comment.author}}/{{ post.comment.permlink }}" target="_blank">{{ post.comment.title }}</a></li> {% endfor %} </ul> ``` ![image.png](https://files.peakd.com/file/peakd-hive/june0620/2VB8d6zy-image.png) 意思就是从 `Views.py` 获取的目录反复用li标签渲染到页面。 还差一步,需要把 template 路径设置到 `Settings.py`。 ``` TEMPLATES = [ { ... 'DIRS': [os.path.join(BASE_DIR, 'templates')], ... }, ] ``` ![image.png](https://files.peakd.com/file/peakd-hive/june0620/v8wqyF9T-image.png) ##### 运行 运行本地服务器后在 URL 加 `@june0620`后缀访问,成功。 ![image.png](https://files.peakd.com/file/peakd-hive/june0620/moj4HSo6-image.png) . . . . [Cookie 😅] Python 3.7.4 Django 2.2.4 steem-python 1.0.1 goorm IDE 1.3
post_id | 86,671,892 |
---|---|
author | june0620 |
permlink | python-10-django-3-post |
category | hive-101145 |
json_metadata | {"tags":["hive-101145","cn","cn-stem","steemstem","mini","zzan","sct-cn","sct-freeboard","dblog","sct"],"image":["https:\/\/cdn.pixabay.com\/photo\/2019\/05\/14\/17\/07\/web-development-4202909_1280.png","https:\/\/files.peakd.com\/file\/peakd-hive\/june0620\/Ohk3u4QJ-image.png","https:\/\/files.peakd.com\/file\/peakd-hive\/june0620\/3wcNGQdX-image.png","https:\/\/files.peakd.com\/file\/peakd-hive\/june0620\/VXI3eDKg-image.png","https:\/\/files.peakd.com\/file\/peakd-hive\/june0620\/2VB8d6zy-image.png","https:\/\/files.peakd.com\/file\/peakd-hive\/june0620\/v8wqyF9T-image.png","https:\/\/files.peakd.com\/file\/peakd-hive\/june0620\/moj4HSo6-image.png"],"links":["https:\/\/peakd.com\/hive-105017\/@june0620\/python-9-django-2-steem-python-steem"],"app":"steemcoinpan\/0.1","format":"markdown","canonical_url":"https:\/\/www.steemcoinpan.com\/@june0620\/python-10-django-3-post"} |
created | 2020-07-12 13:06:42 |
last_update | 2020-07-12 13:06:42 |
depth | 0 |
children | 1 |
net_rshares | 33,784,273,813,726 |
last_payout | 2020-07-19 13:06:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 11.496 SBD |
curator_payout_value | 10.619 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 2,355 |
author_reputation | 219,336,602,045,061 |
root_title | "[Python #10] [Django #3] 获取我的POST列表并显示在网页" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
mangou007 | 0 | 8,628,946,717 | 5.43% | ||
gerber | 0 | 36,392,695,120 | 6.8% | ||
ezzy | 0 | 456,897,593,648 | 6.8% | ||
exyle | 0 | 667,564,816,712 | 6.8% | ||
jphamer1 | 0 | 2,511,913,070,776 | 100% | ||
bert0 | 0 | 27,833,809,329 | 5.43% | ||
justyy | 0 | 11,917,995,072,371 | 55.68% | ||
jack8831 | 0 | 25,530,098,143 | 25% | ||
happyukgo | 0 | 10,803,211,869 | 55.68% | ||
thenightflier | 0 | 0 | 50% | ||
virus707 | 0 | 1,394,083,906,363 | 4% | ||
dexpartacus | 0 | 533,068,273 | 50% | ||
robinlee | 0 | 255,436,022 | 55.68% | ||
pixelfan | 0 | 11,712,468,120 | 2.15% | ||
ilovemylife | 0 | 442,916,483,916 | 31% | ||
steempostitalia | 0 | 3,337,435,676 | 50% | ||
rainyapril | 0 | 257,601,099 | 55.68% | ||
chetanpadliya | 0 | 14,246,772,054 | 40% | ||
kangnajiang | 0 | 88,721,310 | 55.68% | ||
kikima | 0 | 351,593,877 | 55.68% | ||
geass | 0 | 289,939,611 | 55.68% | ||
karja | 0 | 57,853,635,744 | 3% | ||
accelerator | 0 | 24,585,053,541 | 6% | ||
june0620 | 0 | 340,658,266,472 | 100% | ||
superbing | 0 | 2,192,033,395 | 55.68% | ||
dailyfortune | 0 | 1,753,985,995 | 55.68% | ||
dailystats | 0 | 2,807,321,458 | 55.68% | ||
khaleelkazi | 0 | 2,874,775,638 | 6.8% | ||
flamingirl | 0 | 1,383,246,742 | 5.43% | ||
miti | 0 | 116,180,625 | 7% | ||
pataty69 | 0 | 4,695,641,372 | 5% | ||
jianan | 0 | 28,768,149,866 | 55.68% | ||
emrebeyler | 0 | 0 | 6.8% | ||
cnbuddy | 0 | 1,394,202,756 | 0.1% | ||
daxiang | 0 | 102,753,600 | 55.68% | ||
anxin | 0 | 1,367,459,146 | 55.68% | ||
girolamomarotta | 0 | 45,271,134,675 | 50% | ||
mehta | 0 | 332,583,441,448 | 40% | ||
mmmmkkkk311 | 0 | 860,696,796,977 | 100% | ||
bji1203 | 0 | 684,783,101,516 | 100% | ||
nealmcspadden | 0 | 26,388,121,637 | 6.8% | ||
purefood | 0 | 0 | 6.8% | ||
udabeu | 0 | 9,298,244,313 | 30% | ||
nean | 0 | 256,359,216 | 55.68% | ||
foodielifestyle | 0 | 246,456,604 | 55.68% | ||
woolfe19861008 | 0 | 1,169,866,075 | 55.68% | ||
marsswim | 0 | 94,811,694,332 | 51% | ||
dailychina | 0 | 3,265,694,937 | 55.68% | ||
vincenthan | 0 | 263,959,366 | 55.68% | ||
dongfengman | 0 | 6,064,131,630 | 55.68% | ||
serenazz | 0 | 594,592,363 | 55.68% | ||
yedda | 0 | 260,280,219 | 55.68% | ||
zasilla | 0 | 260,223,555 | 55.68% | ||
tatylayla | 0 | 1,054,176,982 | 100% | ||
fishaa | 0 | 0 | 55.68% | ||
also.einstein | 0 | 8,552,674,051 | 100% | ||
mad-runner | 0 | 374,494,863 | 50% | ||
ethanlee | 0 | 2,516,184,446 | 55.68% | ||
twinsnicole | 0 | 271,803,655 | 55.68% | ||
deepthinking | 0 | 264,738,576 | 55.68% | ||
dhingvimal | 0 | 2,358,975,031 | 40% | ||
onepercentbetter | 0 | 15,896,457,443 | 10% | ||
fanso | 0 | 762,914,674 | 55.68% | ||
lucky2015 | 0 | 288,286,537,192 | 80% | ||
lilypang22 | 0 | 682,393,639 | 55.68% | ||
fishcc | 0 | 0 | 55.68% | ||
gghite | 0 | 50,029,212,231 | 100% | ||
zens | 0 | 261,731,860 | 55.68% | ||
andrewma | 0 | 2,883,664,717 | 11.13% | ||
steemitvip | 0 | 261,768,880 | 55.68% | ||
regals | 0 | 259,207,552 | 55.68% | ||
joelone | 0 | 264,661,163 | 55.68% | ||
sweet-jenny8 | 0 | 11,621,534,756 | 55.68% | ||
ravenkim | 0 | 7,264,794,637 | 100% | ||
merlion | 0 | 3,302,444,500 | 10% | ||
robertyan | 0 | 15,897,936,054 | 100% | ||
freegon | 0 | 37,987,005,064 | 100% | ||
digital.mine | 0 | 119,924,817,505 | 1% | ||
newsnownorthwest | 0 | 1,127,845,563 | 55% | ||
weicomenew | 0 | 259,602,095 | 55.68% | ||
laiyuehta | 0 | 2,564,664,800 | 55.68% | ||
turtlegraphics | 0 | 1,314,766,168 | 55.68% | ||
spi-postit | 0 | 126,822,166 | 50% | ||
dlike | 0 | 57,046,652,005 | 3.9% | ||
pet.society | 0 | 23,606,694,443 | 5% | ||
witnesstools | 0 | 3,776,682,694 | 55.68% | ||
ilovecoding | 0 | 3,485,926,691 | 55.68% | ||
nineteensixteen | 0 | 23,549,426,651 | 100% | ||
steemfuckeos | 0 | 1,708,799,139 | 55.68% | ||
sindong | 0 | 261,116,656,505 | 40% | ||
edgarare1 | 0 | 17,318,553,284 | 11% | ||
samsemilia7 | 0 | 1,268,030,212 | 6.8% | ||
primeradue | 0 | 903,489,060 | 6.8% | ||
top.rewards.club | 0 | 201,392,271 | 50% | ||
ctime | 0 | 669,853,861,224 | 10% | ||
hungrybear | 0 | 258,213,736 | 10% | ||
lolasophiedanton | 0 | 132,668,922 | 6.8% | ||
holydog | 0 | 14,436,415 | 37% | ||
hunter-man | 0 | 88,557,226 | 27.5% | ||
minigame | 0 | 11,445,700,618,836 | 49.2% | ||
kr-fund | 0 | 3,489,046,912 | 25% | ||
abojasim880 | 0 | 606,100,129 | 100% | ||
blockcleaner | 0 | 10,932,700,653 | 55.68% | ||
zzan.co3 | 0 | 635,205,094 | 100% | ||
steem.leo | 0 | 8,210,569,649 | 6.8% | ||
cplusplus | 0 | 3,437,712,724 | 55.68% | ||
leo.voter | 0 | 636,974,332 | 6.8% | ||
chrono.leo | 0 | 0 | 3.4% | ||
justsoso | 0 | 876,769,280 | 55.68% | ||
freegon.sct | 0 | 1,889,405,850 | 100% | ||
tokenindustry | 0 | 1,751,282,782 | 45% | ||
sct.krwp | 0 | 370,603,134,987 | 0.65% | ||
maxuvd | 0 | 5,004,898,398 | 6.8% | ||
longhash | 0 | 784,018,162 | 55.68% | ||
cnlifes | 0 | 0 | 55.68% | ||
llfestyle | 0 | 196,780,156 | 55.68% | ||
bcm | 0 | 52,886,722,619 | 2.21% | ||
sct.curator | 0 | 20,521,287,723 | 23.8% | ||
cnbuddy-reward | 0 | 35,820,266 | 0.05% | ||
erlcet | 0 | 0 | 55.68% | ||
bcm.dblog | 0 | 75,709,241 | 2.65% | ||
bcm.zzan | 0 | 0 | 2.65% | ||
deepcrypti8 | 0 | 0 | 55.68% | ||
wilhb82 | 0 | 0 | 55.68% | ||
armylove | 0 | 146,522,717 | 50% | ||
blue-berry | 0 | 182,231,780 | 25% | ||
amatamar | 0 | 218,472,043 | 50% | ||
sexybeach | 0 | 3,492,698,830 | 55.68% | ||
suckmydick | 0 | 1,749,000,534 | 55.68% | ||
chromebook | 0 | 1,707,814,360 | 55.68% | ||
ericandryan | 0 | 6,340,601,164 | 55.68% | ||
dev.supporters | 0 | 131,324,593,764 | 10% | ||
justyy222 | 0 | 1,733,703,781 | 55.68% | ||
krwp.abc | 0 | 0 | 0.41% |
@june0620 transfered 1.0 KRWP to @krwp.burn. voting percent : 0.65%, voting power : 79.42%, steem power : 1847324.24, STU KRW : 1200. @june0620 staking status : 50 KRWP @june0620 limit for KRWP voting service : 0.1 KRWP (rate : 0.002) What you sent : 1.0 KRWP Refund balance : 0.9 KRWP [45041551 - 259196e521b115f970aeb7f048adf6b0eecb757d]
post_id | 86,671,933 |
---|---|
author | sct.krwp |
permlink | re--python-10-django-3-post-20200712t130930262z |
category | hive-101145 |
json_metadata | {"tags":["hive-101145","cn","cn-stem","steemstem","mini","zzan","sct-cn","sct-freeboard","dblog","sct"]} |
created | 2020-07-12 13:09:33 |
last_update | 2020-07-12 13:09:33 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2020-07-19 13:09:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 436 |
author_reputation | 10,000,000,000,000 |
root_title | "[Python #10] [Django #3] 获取我的POST列表并显示在网页" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |