سؤال

I'm stuck with a little problem, at the moment i'm developing template tags for an app, and I have to import a form, .forms import MyModelForm doesn't work because is not in the same directory ...

I did a trick for the model with the get_model('app', 'Model'), but I didn't find anything like that for forms.

My structure is really classic :

app
|-templates
|-templatestags
| |-__init__
| |-app_tags.py
|-forms.py
|-models.py
|-views.py

I want to keep my app independent from the project.

Cheers

هل كانت مفيدة؟

المحلول

Try this

from ..forms import MyModelForm

For more info on imports, please read PEP 328.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top