In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to use Fixtures in Django. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
Basic configuration
Configure the following in settings.py:
FIXTURE_DIRS = ('/ path/to/api/fixtures/',)
In the app to be tested, add the directory fixtures
Under the newly added fixtures directory, create a new file myapp.json with a name of your own and a suffix of .json.
Configure myapp.json
The format of the content in the file is as follows. In actual use, delete the actual situation, use data, and delete comments. If you need more than one piece of data, you can write more {} content:
[{
"model": "myapp.user", # database name
"Competition": "a864340d850f484bb89ea2981047bc5e", # data to be imported
"fields": {# the field to be imported. The field name is the same as the field in the database (models). The value is set according to the actual needs.
"username": "zhangsan"
User_num: 00000
"zh_name": "Zhang San"
"mobile": "187 12345678"
"mail": "zhangsan@abc.com"
"is_deleted": false
"create_time": "2013-01-16"
"update_time": "2013-01-16"
}
}
]
Configure tests.pyclass Test_user_name (TestCase):
'' whether the tester name is normal''
Fixtures = ['myapp.json'] # Select the user data you want to import to test here
Def test_user_name (self):
User = User.objects.get (username='zhangsan')
Self.assertEqual (user.name, "zhangsan")
After reading the above, do you have any further understanding of how to use Fixtures in Django? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.