I have a form on the homepage of mydomain.com that instructs people to
submit their email address and we'll notify them when we launch our
service. For those visitors that submit the form, I want to store the
referer. I am able to print out the HTTP_REFERER on the same template
as the form but I cannot figure out how to store the correct referer
in the database.

I have the following in my views.py, the lines commented out are
approaches I took that were unsuccessful. I realize I could try a
hidden form variable but am wondering if there is something else I can
do.

# Create your views here.
from django.http import HttpResponseRedirect
from django.forms import ModelForm
from django.shortcuts import render_to_response
from permission.models import Sneezer

class SneezerForm(ModelForm):
        class Meta:
                model = Sneezer
                exclude = ['ip_address', 'referer', 'timestamp']

def add_sneezer(request):
        if request.method == 'POST':
                #       referer = request.META.get("HTTP_REFERER", "")
                #       line above generates an empty value in database
                data = request.POST
                #data = data.copy()
                #data.update({"referer" : referer})
                form = SneezerForm(data)
                if form.is_valid():
                        new_sneezer = form.save(commit=False)
                        new_sneezer.ip_address = 
request.META.get("REMOTE_ADDR", "")
                        #new_sneezer.referer = request.META.get("HTTP_REFERER", 
"")
                        #stores mydomain.com as the value every time, thus its 
storing the
referer of the POST
                        new_sneezer.save()
                        return render_to_response('thanks.html')
        else:
                form = SneezerForm(initial={'referer':
request.META.get("HTTP_REFERER", "")})
                return render_to_response('index.html', { 'form': form,
'original_referer': request.META.get("HTTP_REFERER", "") })

def index(request):
        form = SneezerForm(initial={'referer':
request.META.get("HTTP_REFERER", "")})
        return render_to_response('index.html', { 'form': form,
'original_referer': request.META.get("HTTP_REFERER", "") })


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to