V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
yuningmiao
V2EX  ›  Python

新手 django 的简单问题

  •  
  •   yuningmiao · 2017-05-17 12:42:37 +08:00 via iPad · 2037 次点击
    这是一个创建于 2536 天前的主题,其中的信息可能已经有所发展或是发生改变。
    大家好,第一次做网站,以前只做过静态的 html,经验相当有限,有个简单问题请教一下。比如说我现在已经有一个写好的 html 网页,里面有各种下拉菜单,文本框,复选框之类的。然后我现在打算用 django 做这个网站,通过看教程我觉得这个步骤叫 template。那如果我要 django 把这些表单的内容全部收集起来写入数据库,我就得基本上重写整个这个写好的网页吗?有什么其他更好的方法吗?
    7 条回复    2017-05-21 12:37:16 +08:00
    Anybfans
        1
    Anybfans  
       2017-05-17 13:09:01 +08:00
    不需要重写页面的。直接渲染了就可以用了。
    WhiteLament
        2
    WhiteLament  
       2017-05-17 22:43:50 +08:00
    ```
    {% for item in form_pathinput %}
    <div class="form-group">
    <div class="col-lg-11">{{item}}</div>
    </div>
    {% endfor %}
    ```
    WhiteLament
        3
    WhiteLament  
       2017-05-17 22:44:42 +08:00
    接上,不需要重写,比如有多个输入框,模板里只需要略加改动就可以了类似上面的
    yuningmiao
        4
    yuningmiao  
    OP
       2017-05-18 09:02:26 +08:00
    @WhiteLament
    神人没看懂啊,能不能再麻烦您看一下比如说下面这个片段该怎么改?多谢多谢
    <li id="li_11" >
    <label class="description" for="element_11">验证码 </label>
    <div>
    <input id="element_11" name="element_11" class="element text medium" type="text" maxlength="255" value=""/>
    </div>
    </li> <li id="li_12" >
    <label class="description" for="element_12">姓名 </label>
    <div>
    <input id="element_12" name="element_12" class="element text medium" type="text" maxlength="255" value=""/>
    </div>
    </li>
    yuningmiao
        5
    yuningmiao  
    OP
       2017-05-18 09:17:48 +08:00
    @WhiteLament 另外还一个小问题要请教一下,比如说我这个页面上有 100 个 check box,那我要记录结果到数据库里就要在数据库里创建对应的 100 个条目嘛?
    WhiteLament
        6
    WhiteLament  
       2017-05-19 11:26:09 +08:00
    @yuningmiao 大概形如这样,我觉得你应该再看一下关于模板的文档
    {% for item in form_list %}
    <li id="{{item.listid}}" >
    <label>{{item.lable}}</label>
    <div>
    <input id="{{item.inputid}}" name="{{item.name}}" />
    </div>
    </li>
    {% endfor %}

    至于你说的 100 个 check box,要看具体结构设计
    yuningmiao
        7
    yuningmiao  
    OP
       2017-05-21 12:37:16 +08:00
    @WhiteLament 多谢多谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5362 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 05:52 · PVG 13:52 · LAX 22:52 · JFK 01:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.