from django.db import models

class HisTube (models.Model):
    title = models.CharField ('title', max_length = 100)
    image = models.CharField ('thumbn', max_length = 200)
    url = models.CharField ('Video URL', max_length = 200)
    length = models.CharField ('length', max_length = 50)
    cname = models.CharField ('channel name', max_length = 100)
    curl = models.CharField ('channel url', max_length = 100)

I'd like to save the values ​​intitleandimageof this models.py in view, but I don't know how.

  • Answer # 1

    I'm sorry for what I made, but there is a way like this.



    Specify post in the method of the

    form tag. And in the form element, you can receive data by making{{form.used_date}}like the code above. See form.py for the neighborhood.

    The part that receives this is written in view.py.
    For example, create a method namedpostand specify request as an argument. Then you can receive the contents of the form withrequest.POST, and then you can access the contents using the method used in the Python dictionary. When saving to the database, use (model name) .object.create (view.py line 64).