Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using the following code to upload a image file to server,
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>test</title>
	</head>
	<body>
        <form enctype= "multipart/form-data" method = "post" action = "http://127.0.0.1:8000/show_test/">
            <input type = "file" name = "image" />
            <input type = "submit"  value = "submit"/>
        </form>
	</body>
</html>


I use the request.FILES[iamge_file_name] to retrive the iamge file data, but how tosave it to my model?

models.py

Python
class TUser(models.Model):
    """ table t_user model """
    
    name = models.CharField(max_length=50)
    # enciphered password.
    password = models.CharField(max_length=200, blank=True)
    email = models.EmailField()
    image = models.ImageField(
        upload_to='images/photos/%Y/%m/%d',
        height_field=48, width_field=48, null=True, blank=True)
    website = models.URLField(blank=True, null=True)

    class Meta:
        db_table = "t_user"
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900