问题描述
所以我已经有一个数据库设置,其中已经插入了几列和几行.我正在尝试创建一个视图,您只需将信息输入表单并按提交,然后将添加一行包含您刚刚输入的信息的 MySQL 数据库.
So I already have a database setup with a few columns and a few rows already inserted in. I'm trying to create a view that you would just input information into a form and press Submit, then a row would be added to the MySQL database with the information you just typed in.
我相信您可以使用 admin 执行此操作,但我想在没有 admin 的情况下尝试,我不确定这是否可行?到目前为止,我一直在使用 MySQL 命令行添加行..
I believe you can do this with admin, but I would like to try without admin and I'm not sure if this is possible? I've been using the MySQL commandline to add rows as of now..
推荐答案
当然这是可能的,这是数据驱动网站的构建块.您可以使用 Daniel 建议的 ModelForm(他们免费提供内置验证和 HTML 标记)来轻松地将您的模型映射到前端表单.首先从 django 教程或文档开始可能会有所帮助.
Of coures this is possible this is a building block for data driven websites. You can use a ModelForm as Daniel suggested (they offer built in validation and HTML markup for FREE) to easily map your model to a front end form. It would probably be beneficial to start with django tutorial or documentation first.
最基本的,你所要做的就是实例化你的模型
At the the very basic, all you have to do is instantiate your model
new_entry = YourModel(name='me', age='222', about='stackoverflow')
然后保存
new_entry.save()
这会将其作为新行添加到您的数据库中.
This adds it as a new row to your db.
https://docs.djangoproject.com/en/dev/主题/数据库/模型/
这篇关于Django - 向 MySQL 数据库添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)