I have no idea what you mean by "stop working" -- without knowing what the
code looked like before, I don't know how it worked before. The usual rule
is that if something worked before, and doesn't work now, then the problem
is in something that you did in between.

Now if this is a new view, and has never worked at all, then that's
different.

At a first glance, you are using "render_to_response" in your view. This
method creates a Context object out of the dictionary that you pass it (in
your case, {'form': form} ).

A Context object doesn't know anything about the request, so {{ request.path
}} won't work in the template. It also doesn't have any ContextProcessors
applied, so you won't have access to context variables like {{ STATIC_URL
}}. The *only* variable that will be available in your template is {{ form
}}, because you passed it in.

What you want is a RequestContext object, rather than a Context object. You
can get one in your template, by adding one parameter to render_to_response:

    from django.template import RequestContext
    ...
    def contact(request):
        ...
        render_to_reponse(
            '/var/djcode/oneadmin/templates/oneadmissions/contact.html',
            {'form': form},
            context_instance=RequestContext(request)
        )

That should give you a functioning template.

Ian

On Fri, Jun 10, 2011 at 9:27 PM, raj <nano.ri...@gmail.com> wrote:

> I also noticed one more thing, in general, all html functions stopped
> working with render_to_response i think. Like i have a function that
> gets the current path ({% request.path == ".." %}). That also isn't
> working. And even when I hard-code it, it doesn't make a difference.
> any suggestions?
>
> On Jun 11, 12:17 am, raj <nano.ri...@gmail.com> wrote:
> > Another thing i just noticed, When i view the source of my contact
> > form, all the css/javascript includes are missing part of the path
> > where i placed a {{ STATIC_URL }} tag. Why isn't this tag being
> > rendered? Thank you.
> >
> > On Jun 11, 12:14 am, raj <nano.ri...@gmail.com> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Hey guys, Whenever i try and add a contact form (from the django book)
> > > into my current website, all my css/javascripts stop working. What is
> > > the issue? Here are my codes:
> >
> > > #views.py
> >
> > > def contact(request):
> > >     if request.method == 'POST':
> > >         form = ContactForm(request.POST)
> > >         if form.is_valid():
> > >             cd = form.cleaned_data
> > >             send_mail(
> > >                 cd['subject'],
> > >                 cd['message'],
> > >                 cd.get('email', 'nore...@example.com'),
> > >                 ['siteow...@example.com'],
> > >             )
> > >             return HttpResponseRedirect('/contact/thanks/')
> > >     else:
> > >         form = ContactForm()
> > >     return render_to_response('/var/djcode/oneadmin/templates/
> > > oneadmissions/contact.html', {'form': form})
> >
> > > #forms.py
> >
> > > from django import forms
> >
> > > class ContactForm(forms.Form):
> > >     subject = forms.CharField()
> > >     email = forms.EmailField()
> > >     message = forms.CharField()
> > >     name = forms.CharField()
> >
> > > #urls.py
> > > urlpatterns = patterns('',
> > >     ...
> > >      (r'^contact-form/', views.contact),
> > >     ...
> > >      )
> >
> > > I have my static folder and everything created properly, its working
> > > perfectly fine until i input the chapter on forms. Help please!
>
> --
> 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.
>
>


-- 
Regards,
Ian Clelland
<clell...@gmail.com>

-- 
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