pixabay https://cdn.pixabay.com/photo/2019/03/12/20/27/kanban-4051777_1280.jpg 在[上回](https://steemit.com/hive-101145/@june0620/3sz4dp-python-17-django-10-ui),有一个地方我用硬编码,因我不会用变量。 > action 值先用硬编码 /@june0620/search赋值,账号应该用变量,但目前还不知道怎么用变量。 没办法,谁让我是django初学者呢。 当时用我的账号硬编码,所以无法搜索他人的文章。今天解决这个问题吧。 从URL获取账号赋值给action参数。幸好Django提供获取URL的方法`{{ request.path }}`,通过Template filters创建一个过滤器应该可以过滤账号了。 ##### templatetags 在 templatetags 文件夹 > post_extras.py文件里注册一个过滤器。过滤的方法用正规表达式最好不过,但我不太会用正规表达式。哎~没事儿,学吧。 经过我精心的搜索,搜出了一个非常好用的正规表达式检查器。https://regex101.com/r/cO8lqs/4 就用你了~ ``` import re ... ... @register.filter def get_account_form_url(path: str): account = re.search(r'@[a-z0-9-.]*', path) print(path) print(account.group(0)) return account.group(0) if account else None ``` <p>  ##### base.html 在 base.html 载入过滤器, form action 也改用过滤器就OK了。 ``` {% load post_extras %} ... ... <form action="/{{ request.path | get_account_form_url }}/search/" method="get"> <label >Tags: </label> <input id="tags" type="text" name="tags" value=""> <label >Titles: </label> <input id="titles" type="text" name="titles" value=""> <label >Texts: </label> <input id="texts" type="text" name="texts" value=""> <input type="submit" value="Search"> </form> ``` <p>  ##### 结果 哈哈,现在可以搜索萍萍(@annepink)的熊孩纸文章了。😄  *** **[Cookie 😅]** Python 3.7.4 Django 2.2.4 steem-python 1.0.1 goorm IDE 1.3 参考文章: https://medium.com/@chrisjune_13837/%EC%A0%95%EA%B7%9C%EC%8B%9D-%ED%8A%9C%ED%86%A0%EB%A6%AC%EC%96%BC-%EC%98%88%EC%A0%9C%EB%A5%BC-%ED%86%B5%ED%95%9C-cheatsheet-%EB%B2%88%EC%97%AD-61c3099cdca8
author | june0620 |
---|---|
permlink | python-18-django-11-form-action-qgjli6 |
category | hive-105017 |
json_metadata | {"app":"peakd/2020.09.4","format":"markdown","tags":["cn","whalepower","palnet","python","dblog","dev","django","goorm"],"users":["june0620","register.filter","annepink","chrisjune"],"links":["https://steemit.com/hive-101145/@june0620/3sz4dp-python-17-django-10-ui","https://regex101.com/r/cO8lqs/4","/@annepink","https://medium.com/@chrisjune_13837/%EC%A0%95%EA%B7%9C%EC%8B%9D-%ED%8A%9C%ED%86%A0%EB%A6%AC%EC%96%BC-%EC%98%88%EC%A0%9C%EB%A5%BC-%ED%86%B5%ED%95%9C-cheatsheet-%EB%B2%88%EC%97%AD-61c3099cdca8"],"image":["https://cdn.pixabay.com/photo/2019/03/12/20/27/kanban-4051777_1280.jpg","https://cdn.steemitimages.com/DQmdCAPzAmj4PnJLtWxLSTpgxbU1ZystDbc2E1PYcD6MNkS/image.png","https://cdn.steemitimages.com/DQmcQzKTGkiSocuYPrwYPJ3KXvc92ZtnxYWsRANkzK5mc7k/image.png","https://cdn.steemitimages.com/DQmQrQ5RoXTnA5piqTsEUWQd3P9o6w7HJwpxthU9aoBccb7/image.png"]} |
created | 2020-09-12 11:06:12 |
last_update | 2020-09-12 11:06:12 |
depth | 0 |
children | 7 |
last_payout | 2020-09-19 11:06:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 1.364 HBD |
curator_payout_value | 1.202 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,967 |
author_reputation | 118,592,211,436,406 |
root_title | "[Python #18] [Django #11] form action 添加变量(副题:搜索他人搜索)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 0 |
post_id | 99,586,684 |
net_rshares | 10,575,557,741,566 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
chitty | 0 | 303,474,200,077 | 75% | ||
mangou007 | 0 | 8,159,210,070 | 5.04% | ||
slowwalker | 0 | 43,723,549,525 | 50% | ||
bullionstackers | 0 | 369,425,080,051 | 50% | ||
bert0 | 0 | 26,635,065,578 | 5.04% | ||
tumutanzi | 0 | 926,146,203 | 50% | ||
oldstone | 0 | 13,729,527,883 | 50% | ||
dylanhobalart | 0 | 61,472,788,183 | 21% | ||
coldhair | 0 | 892,445,338 | 50% | ||
lotusofmymom | 0 | 458,738,718 | 50% | ||
shenchensucc | 0 | 18,862,236,188 | 30% | ||
khaiyoui | 0 | 340,727,412,998 | 20% | ||
tykee | 0 | 5,531,621,008 | 50% | ||
aafeng | 0 | 42,885,406,832 | 10% | ||
rafaelaquino | 0 | 10,345,235,265 | 100% | ||
tipu | 0 | 3,272,720,749,176 | 9% | ||
kimzwarch | 0 | 8,476,905,131 | 4% | ||
june0620 | 0 | 569,363,879,797 | 100% | ||
minloulou | 0 | 2,323,021,286 | 10% | ||
flamingirl | 0 | 1,304,557,162 | 5.04% | ||
lindalex | 0 | 580,349,302 | 50% | ||
cnbuddy | 0 | 936,111,731,550 | 100% | ||
itchyfeetdonica | 0 | 107,744,533,041 | 50% | ||
nokodemion | 0 | 6,860,883,906 | 100% | ||
kamchore | 0 | 156,294,365,177 | 100% | ||
jim888 | 0 | 395,047,852,696 | 22% | ||
bartheek | 0 | 13,470,758,158 | 4.5% | ||
bji1203 | 0 | 92,616,934,678 | 100% | ||
bala41288 | 0 | 31,422,356,949 | 10% | ||
suhunter | 0 | 961,902,227 | 50% | ||
udabeu | 0 | 9,789,718,932 | 30% | ||
jsj1215 | 0 | 2,500,132,763 | 100% | ||
yasu | 0 | 3,400,102,762 | 100% | ||
happy-soul | 0 | 19,659,967,115 | 4.5% | ||
josevas217 | 0 | 9,823,195,701 | 4.03% | ||
franyeligonzalez | 0 | 559,532,255 | 2.52% | ||
gghite | 0 | 132,126,101,824 | 100% | ||
payroll | 0 | 98,213,393,815 | 2% | ||
julialee66 | 0 | 1,114,631,276,809 | 8.5% | ||
andrewma | 0 | 12,568,321,551 | 50% | ||
wisdomandjustice | 0 | 875,413,936 | 50% | ||
newsnownorthwest | 0 | 7,682,977,925 | 55% | ||
longer | 0 | 1,076,488,576 | 2.25% | ||
suonghuynh | 0 | 8,735,595,006 | 6% | ||
coder-bts | 0 | 5,155,315,984 | 50% | ||
donald.porter | 0 | 7,983,316,447 | 18% | ||
gerdtrudroepke | 0 | 19,122,792,088 | 30% | ||
daath | 0 | 444,897,408 | 100% | ||
veronicalee | 0 | 313,738,797 | 50% | ||
melaniewang | 0 | 8,925,609,135 | 50% | ||
changxiu | 0 | 5,053,333,843 | 50% | ||
laissez-faire | 0 | 77,139,046 | 100% | ||
cherryzz | 0 | 177,671,435,006 | 50% | ||
memeteca | 0 | 632,619,611 | 5.04% | ||
forecasteem | 0 | 65,267,412,443 | 100% | ||
skoroklad | 0 | 700,764,427 | 100% | ||
dam4ik2 | 0 | 711,169,421 | 100% | ||
moneytron | 0 | 4,365,192,701 | 100% | ||
ctime | 0 | 855,528,086,042 | 5% | ||
cpt-sparrow | 0 | 2,728,819,972 | 100% | ||
kryptogames | 0 | 44,281,199,124 | 9% | ||
tina3721 | 0 | 4,865,573,237 | 50% | ||
andyhsia | 0 | 16,007,239,982 | 100% | ||
minigame | 0 | 356,168,964,487 | 100% | ||
royal-jelly | 0 | 24,991,761,448 | 100% | ||
oldstone.sct | 0 | 512,571,668 | 50% | ||
tokenindustry | 0 | 2,875,890,548 | 80% | ||
lemeonna | 0 | 681,109,692 | 11% | ||
cnbuddy-reward | 0 | 78,257,434,980 | 100% | ||
roseofmylife | 0 | 1,878,378,297 | 50% | ||
real3earch | 0 | 1,844,433,146 | 100% | ||
jgb | 0 | 1,540,512,332 | 4.53% | ||
steem-agora | 0 | 11,390,936,307 | 50% | ||
bo022 | 0 | 533,867,233,734 | 100% | ||
toni.pal | 0 | 0 | 0.62% | ||
gitplait | 0 | 70,676,092,522 | 100% | ||
mafia.wallet | 0 | 6,845,104,568 | 40% |
Hi 🙋🏻♀️ @tipu curate
author | annepink |
---|---|
permlink | qgjlp4 |
category | hive-105017 |
json_metadata | {"users":["tipu"],"app":"hiveblog/0.1"} |
created | 2020-09-12 11:10:18 |
last_update | 2020-09-12 11:10:18 |
depth | 1 |
children | 2 |
last_payout | 2020-09-19 11:10:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 22 |
author_reputation | 1,025,803,312,269,923 |
root_title | "[Python #18] [Django #11] form action 添加变量(副题:搜索他人搜索)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 99,586,725 |
net_rshares | 0 |
晚上好,萍萍~ 😄 谢谢tipu
author | june0620 |
---|---|
permlink | re-annepink-qgjlve |
category | hive-105017 |
json_metadata | {"tags":["hive-105017"],"app":"peakd/2020.09.4"} |
created | 2020-09-12 11:14:03 |
last_update | 2020-09-12 11:14:03 |
depth | 2 |
children | 0 |
last_payout | 2020-09-19 11:14:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 16 |
author_reputation | 118,592,211,436,406 |
root_title | "[Python #18] [Django #11] form action 添加变量(副题:搜索他人搜索)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 99,586,747 |
net_rshares | 0 |
<a href="https://tipu.online/hive_curator?annepink" target="_blank">Upvoted 👌</a> (Mana: 18/45)
author | tipu |
---|---|
permlink | re-qgjlp4-20200912t111028 |
category | hive-105017 |
json_metadata | "" |
created | 2020-09-12 11:10:30 |
last_update | 2020-09-12 11:10:30 |
depth | 2 |
children | 0 |
last_payout | 2020-09-19 11:10:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 104 |
author_reputation | 55,900,354,328,870 |
root_title | "[Python #18] [Django #11] form action 添加变量(副题:搜索他人搜索)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 99,586,727 |
net_rshares | 0 |
这么巧 😳难道我收到你艾特我了😂😅😁厉害了俊😎
author | annepink |
---|---|
permlink | qgjlx7 |
category | hive-105017 |
json_metadata | {"app":"hiveblog/0.1"} |
created | 2020-09-12 11:15:09 |
last_update | 2020-09-12 11:16:33 |
depth | 1 |
children | 2 |
last_payout | 2020-09-19 11:15:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 23 |
author_reputation | 1,025,803,312,269,923 |
root_title | "[Python #18] [Django #11] form action 添加变量(副题:搜索他人搜索)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 99,586,758 |
net_rshares | 0 |
实现完搜索功能,尝试搜索你的文章,很成功~ 😃
author | june0620 |
---|---|
permlink | re-annepink-qgjq51 |
category | hive-105017 |
json_metadata | {"tags":["hive-105017"],"app":"peakd/2020.09.4"} |
created | 2020-09-12 12:46:21 |
last_update | 2020-09-12 12:46:21 |
depth | 2 |
children | 1 |
last_payout | 2020-09-19 12:46:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 23 |
author_reputation | 118,592,211,436,406 |
root_title | "[Python #18] [Django #11] form action 添加变量(副题:搜索他人搜索)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 99,587,650 |
net_rshares | 0 |
🥰✌🏻
author | annepink |
---|---|
permlink | qgjr4t |
category | hive-105017 |
json_metadata | {"app":"hiveblog/0.1"} |
created | 2020-09-12 13:07:45 |
last_update | 2020-09-12 13:08:06 |
depth | 3 |
children | 0 |
last_payout | 2020-09-19 13:07:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 3 |
author_reputation | 1,025,803,312,269,923 |
root_title | "[Python #18] [Django #11] form action 添加变量(副题:搜索他人搜索)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 99,587,921 |
net_rshares | 0 |
I have picked your post for my daily hive voting initiative, Keep it up and Hive On!!
author | chitty |
---|---|
permlink | re-python-18-django-11-form-action-qgjli6-20200913t000227 |
category | hive-105017 |
json_metadata | "" |
created | 2020-09-13 00:02:30 |
last_update | 2020-09-13 00:02:30 |
depth | 1 |
children | 0 |
last_payout | 2020-09-20 00:02:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 86 |
author_reputation | 86,901,300,608,582 |
root_title | "[Python #18] [Django #11] form action 添加变量(副题:搜索他人搜索)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 99,596,270 |
net_rshares | 0 |