views.py
def bing1(request): template=loader.get_template("bin1.html") #*******************1****************************** #c=Context({}) #context={"title":"日本語の世界に入ってくだい!","time":datetime.datetime.now()} #*******************1****************************** #*******************2****************************** #title="日本語の世界に入ってくだい!" #time=datetime.datetime.now() #context={} #*******************2****************************** root = os.listdir(pic_root) list_root=[] for r in root: list_root.append(r) data=["相澤","ゆい","あやみ","まりあ","鈴村","遥か","飛鳥","小野泰明", "七海奈々", "葵司","山田","asuka","......"] context={"title":"日本語の世界に入ってくだい!","time":datetime.datetime.now(),"person":["武田華恋",11,"mikami@gmail.com"],"jyoyu":data,"pic":list_root,"num":len(root)} request_context = RequestContext(request, context) request_context.push(locals()) html=template.render(context=locals(), request=request) return HttpResponse(html)urls.py
urlpatterns = [ path("bing1/", views.bing1, name="bing1") ]setting.py (在web_/blog下建立目录static,在static建立pic,pic放入图片)
Pic_DIR=__file__ +"/blog" STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(Pic_DIR,"static/pic") ]bin1.html
<!DOCTYPE html><html lang="ja"> <head> <title>{{context.title}}</title> <style type="text/css"> <!-- img{ float: left; width: 100px; height:150px; vertical-align:middle; } .box{ float: left; color:black; font-size:12px; text-align:leftwards; } .box img { width:40%; 1.实际显示宽5%,高10%,此处与2一起控制一行图片个数。 heght:10%; } txt{ height:23px; width:75px; text-align:center; } --> </style> </head> <body> {% if context.person.1 < 18 %} <h3 align="center">アダルトがないとしたら入れないでください!</h3> {% else %} <h3 align="center">もうアダルトになって入れでください!名前:{{context.person.0}}</h3> {% endif %} <div> {% if context.pic %} {% for li in context.pic %} <div style="float:left;width:12.5%;"> 2.实际显示宽5%,高10%,此处与1一起控制一行图片个数。 {% load static %} <div class="box" > <a href="/static/{{li}}"><img src="/static/{{ li }}" ></a> </div> <div class="box" > <p> 名前:{{context.person.0}} <br> 年目:{{context.person.1}} <br> メール:{{context.person.2}} <br> </p> </div> </div> {% empty %} <li>no!</li> {% endfor %} {% endif %} </div> {% load mydigit %} <br> <br> <p align="right">数量:{{context.num | mydigit:4}} </p> <h2 align="right">时间:{{context.time | date:"Y-m-d H:i:s" }}</h2> </body> </html>