Django - 将行添加到MySQL数据库 [英] Django - Add rows to MySQL database

查看:200
本文介绍了Django - 将行添加到MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经有一个数据库设置,其中已经插入了几列和几行。我正在尝试创建一个视图,您只需将信息输入到表单中,然后按提交,然后将一行添加到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.

我相信你可以用管理员这样做,但我想尝试没有管理员,我不知道是否这个有可能?我一直在使用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/topics/db/models/

这篇关于Django - 将行添加到MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆