On Sat, Aug 13, 2011 at 8:18 AM, Petey <efri...@gmail.com> wrote:

> I have a login/logout application - it works within its defined view
> (login/views.py) and templates (templates/login/index.html).
>
> I want to port this app so it will be displayed in base.html. The main
> problem is that I don't really know how to import this app correctly to
> base.html.
>
>
FYI the terminology of "importing" an app into a template is a bit
confused/confusing, we don't, in Django, import apps into templates. There
is no concept in Django that quite matches those words, although loading
custom template tags from an application comes close.

If I use code pasted below it does only display correctly on localhost/login
> page instead of localhost. On pages containing other forms it will display
> other form instead of my login form.
>
> How can I import login form to global template (base.html) and how I can
> differentiate forms from different apps?
>

Your template code fragment uses a context variable named "form". That
template code works for your login/logout pages presumably because your
login.views.index and login.views.logout_view supply the correct "form"
variable in the context used to render the template.

Including that fragment in your base.html file means that you are expecting
every view that renders a template which ultimately extends from base.html
to provide a context variable named "form" that is the login/logout form.
That's not working because apparently you've got some other views that also
use this name "form" for some other kind of form, and that other form is
what you see rendered in this template fragment instead. If you have views
that provide no variable named "form" in the context, then this bit of
template code will show no form at all.

Essentially by including this HTML fragment in your base template you have
put the template-side of your login/logout app into all your templates, but
that does not accomplish the necessary piece of also incorporating the
Python code side of populating the template context with the correct
variables for the template side.

What you probably want to be doing is creating a custom template tag (to be
specific, probably an inclusion tag) in your login/logout app. You can then
use that template tag in your base template to render the login/logout form.
See the docs here:
https://docs.djangoproject.com/en/1.3/howto/custom-template-tags/

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to