tags:

views:

60

answers:

2

part of forms.py

class FormPublicar(forms.ModelForm):

class Meta:
    model = Publicacao
    exclude = ('usuario', 'aprovado', 'cadastrado_em', 'slug')

def enviar(self):
    titulo = 'mensagem enviada pelo site'
    destino = self.cleaned_data['emailp']
    mensagem = u"""
    Message that will be sent after completing the form.
    Here I must pass a link to the full URL into the body of the email, something like:
    [ 1 ]http://www.domain.com/item/playstation3/
                         /view/slug/   
    """  % self.cleaned_data

    send_mail(
        subject = titulo,
        message = mensagem,
        from_email = '[email protected]',
        recipient_list =[destino],
        )

[ 1 ] I read about the "reverse", tried to mount url + view + parameter. But I could not generate the link correctly, did a number of ways but could not.

I need to pass the domain name+view+parameter slug that is generated after completing the form.

For the recipient of e-mail see the correct link.

Can anyone help me? Thanks in advance.

A: 

Using reverse() is normally the proper way to generate the portion of the URL without the domain. For example, if your URL config contains something like the following:

(r'^item/(?P<item>[-%\w]+)/view/(?P<slug>[-\w]+)$', 'my_view_function')

Then the following call

reverse('my_view_function', kwargs={'item': 'playstation3', 'slug': 'my-slug'})

should return /item/playstation3/view/my-slug.

Preferably, your model Publicacao should define a get_absolute_url method that returns the actual URL for the model instance. See http://docs.djangoproject.com/en/1.2/ref/models/instances/#get-absolute-url.

The domain name part could be retrieved using the Sites framework:

>>> from django.contrib.sites.models import Site
>>> s = Site.objects.get_current()
>>> s.domain
u'localhost:8000'

Of course, you will have to configure the domain of your site properly. See also http://docs.djangoproject.com/en/1.2/ref/contrib/sites/#getting-the-current-domain-for-full-urls.

Bernd Petersohn
A: 

Bernd, thanks. About the "reverse" I already knew.

A short example. here is only a matter of identation. http://pastebin.ca/1977489

Thanks and I apologize, I'm still studying Django.

Érico
Can you show the URL configuration of the view function that should be called when the recipient of that email clicks on the link you want to include in the message body?
Bernd Petersohn