autocomplete django template context variables

is there a way to autocomplete the variables passed into the template by the view in django?

For example, I'm passing a model into template 1 and I'd like to have pycharm show me the handy dropdown with all the model attributes when i type {{ mymodel.

the project structure looks like this
project
 - apps
   - app1
     - templates
       index.html
       about.html
     + migrations
     __init__.py
     views.py
     models.py
 manage.py
prettyPrint();
6 comments
Comment actions Permalink
Could you please show how you pass the model to the template?
0
Comment actions Permalink
class StudentReportCardView(View):
    template_name = "inquest/assessment/student_report_card.html"

    def get(self, request, student_id):
        ctx = dict()
        student_profile = get_object_or_404(users_models.StudentProfile, uuid=student_id)
        taken_assessments = models.StudentAssessments.objects.filter(student=student_profile.user, score__gte=0.0)
        assessments_needing_graded = models.StudentAssessments.objects.filter(student=student_profile.user, score__lt=0.0)

        ctx['student_profile'] = student_profile
        ctx['taken_assessments'] = taken_assessments
        ctx['assessments_needing_graded'] = assessments_needing_graded

        return render_to_response(self.template_name, RequestContext(request, ctx))
prettyPrint();
0
Comment actions Permalink
In this case, PyCharm does not correctly identify that the template is referenced from the code because you're passing a variable, rather than a string literal, as the first argument to render_to_response. We may be able to improve PyCharm's code analysis to handle your situation too; you're welcome to file an issue at http://youtrack.jetbrains.com/
0
Comment actions Permalink
So this is the preferred way in order for PyCharm to recognize the variables?

class StudentReportCardView(View):
    template_name = "inquest/assessment/student_report_card.html"

    def get(self, request, student_id):
        student_profile = get_object_or_404(users_models.StudentProfile, uuid=student_id)
        taken_assessments = models.StudentAssessments.objects.filter(student=student_profile.user, score__gte=0.0)
        assessments_needing_graded = models.StudentAssessments.objects.filter(student=student_profile.user, score__lt=0.0)

        return render_to_response(self.template_name, RequestContext(request, {
            'student_profile': student_profile,
            'taken_assessments': taken_assessments,
            'assessments_needing_graded': assessments_needing_graded,
        }))
prettyPrint();
0
Comment actions Permalink
In the current version of PyCharm, in order for it to recognize the variables, you need to change the code to:
render_to_response("inquest/assessment/student_report_card.html", ...)
prettyPrint();
0
Comment actions Permalink
Ahhhh.

I read that too early in the morning to realize it said "template".  I will open a ticket as Django's class based views make use of the template_name variable

https://docs.djangoproject.com/en/dev/topics/class-based-views/
0

Please sign in to leave a comment.