如何在form.py?
中访问view.py函数的结果我正在尝试使用视图函数的结果作为表单字段的输入
这是我的代码
Views.py
def inc(request):
user_name = request.user.username
u = User.objects.get(username=user_name)
cont = u.accesslevel.numb
Admin.py
class AccessLevelInline(admin.StackedInline):
model = AccessLevel
can_delete = False
verbose_name_plural = 'accesslevel'
# Define a new User admin
class UserAdmin(BaseUserAdmin):
inlines = (AccessLevelInline, )
# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
Form.py
user_name = HOW DO I ACCESS THE USER NAME FROM VIEWS HERE?
u = User.objects.get(username=user_name).accesslevel.prod.split(',')
v=(('---------','---------'),)
for l in u:
v=v+((l.lstrip(),l.lstrip()),)
class ProductForm(forms.Form):
model = ManufactForm
Prod = forms. ChoiceField(choices=v)
答案 0 :(得分:0)
假设您的python文件是Form.py
和View.py
,
在Form.py
的顶部,像这样导入View.py
。
import View
然后您可以调用view.py
文件中的任何功能
View.inc()