我的views.py文件中有以下代码。
def home(request):
fromDate = request.GET.get('fromDate', 'This is a default value')
toDate = request.GET.get('toDate', 'This is a default value')
我想从views.py导入fromDate和toDate到我创建的另一个文件(countries.py(,但每次我都尝试使用
from . import views
我明白错误。
partially initialized module 'website.views' has no attribute 'toDate' (most likely due to a circular import)
即使使用
from website import views # gives the same error
如有任何帮助,我们将不胜感激。
将2变量移动到全局范围内,而不是函数下。
fromDate = request.GET.get('fromDate', 'This is a default value')
toDate = request.GET.get('toDate', 'This is a default value')
def home(request):
...
然后导入到另一个文件,如:
from .view import fromDate, toDate
ps。
按照惯例,python不使用cammelCase,您应重命名为from_date,to_date