It is a memo First, define variables / constants with the file name consts.py Here, consts.py is placed directly under the application directory.
project/application/consts.py
PREF_CHOICE = (
('', 'Prefectures'),
('1', 'Hokkaido'),
('2', 'Aomori Prefecture'),
('3', 'Iwate Prefecture'),
('4', 'Miyagi Prefecture'),
('5', 'Akita'),
('6', 'Yamagata Prefecture'),
('7', 'Fukushima Prefecture'),
('8', 'Ibaraki Prefecture'),
('9', 'Tochigi Prefecture'),
('10', 'Gunma Prefecture'),
('11', 'Saitama'),
('12', 'Chiba'),
('13', 'Tokyo'),
('14', 'Kanagawa Prefecture'),
('15', 'Niigata Prefecture'),
('16', 'Toyama Prefecture'),
('17', 'Ishikawa Prefecture'),
('18', 'Fukui prefecture'),
('19', 'Yamanashi Prefecture'),
('20', 'Nagano Prefecture'),
('21', 'Gifu Prefecture'),
('22', 'Shizuoka Prefecture'),
('23', 'Aichi prefecture'),
('24', 'Mie Prefecture'),
('25', 'Shiga Prefecture'),
('26', 'Kyoto'),
('27', 'Osaka prefecture'),
('28', 'Hyogo prefecture'),
('29', 'Nara Prefecture'),
('30', 'Wakayama Prefecture'),
('31', 'Tottori prefecture'),
('32', 'Shimane Prefecture'),
('33', 'Okayama Prefecture'),
('34', 'Hiroshima Prefecture'),
('35', 'Yamaguchi Prefecture'),
('36', 'Tokushima Prefecture'),
('37', 'Kagawa Prefecture'),
('38', 'Ehime Prefecture'),
('39', 'Kochi Prefecture'),
('40', 'Fukuoka Prefecture'),
('41', 'Saga Prefecture'),
('42', 'Nagasaki Prefecture'),
('43', 'Kumamoto Prefecture'),
('44', 'Oita Prefecture'),
('45', 'Miyazaki prefecture'),
('46', 'Kagoshima'),
('47', 'Okinawa Prefecture'),
)
project/application/views.py
from .consts import PREF_CHOICE
....
Now the variables / constants defined in consts.py are available
If you have defined multiple variables / constants in consts.py and want to use them all in views.py or forms.py, you can use them with from .consts import *
.
Recommended Posts