0
votes

I am working with django in one of my web application where i am also using userena.In userena profile template(profile_detail.html) i have added a anchor tag such as..

<a href = {% url 'send_referral_code'%}>Click here</a>

now here the send_referral_code is name value which is declared in urls.py,the urls.py is..

 from django.conf.urls import patterns, url, include
 from django.conf import settings

 from mail import views

 urlpatterns = patterns('',

    url(r'^$', views.send_referral_code,name='send_referral_code'),

)

and views.py is...

from accounts.models import MyProfile

from django.core.mail import send_mail


def send_referral_code(request):


    referral_code = MyProfile.objects.get(user = request.user)

    send_mail('referral_code','This is Your Referral Code','you@email',['[email protected]'],fail_silently = False)

in mention, both views.py and urls.py resides another app namely 'mail'

and this is my main urls.py ..

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
import photo



urlpatterns = patterns('',
    # Examples:
    #url(r'^$', 'auth.views.home', name='home'),
    # url(r'^shutterstock/', include('shutterstock.foo.urls')),


    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:

    url(r'^accounts/', include('userena.urls')),
    url(r'^user_upload/',include('myprofile.urls')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^showphoto/',include('photo.urls')),
    url(r'^mailing/',include('mail.urls')),




)

from django.conf import settings
if settings.DEBUG:
    urlpatterns += patterns(
        'django.views.static',
        (r'media/(?P<path>.*)',
        'serve',
        {'document_root': settings.MEDIA_ROOT}),
        (r'^something/hard/to/guess/', include('paypal.standard.ipn.urls')), )

now i am getting an error namely Reverse for 'send_referral_code' with arguments '()' and keyword arguments '{}' not found while i am trying to execute my site and its indicating the line

<a href = {% url 'send_referral_code'%}>Click</a>

in my profile_detail.html file of my userena apps.Now how can i solve this or whats the actual problem?

2
Will this be of assistance to you? stackoverflow.com/posts/comments/35235658?noredirect=1 - KhoPhi

2 Answers

0
votes

The reason its not working is because your view code is returning an error. All view methods must return a HttpResponse object.

Any method in Python that doesn't have have a return statement, returns None; and since you don't have a return statement in your view method it is returning None which causes the view to not work.

Try this instead:

from django.shortcuts import redirect

def send_referral_code(request):
    referral_code = MyProfile.objects.get(user = request.user)
    send_mail('referral_code',
              'This is Your Referral Code',
              '[email protected]',
              ['[email protected]'],
              fail_silently=False)
    return redirect('/')
0
votes

I have found the answer of my own,the problem is occuring because ,i have put the variable value as a first argument of the send_mail function parameter,that is,

send_mail('referral_code','This is Your Referral Code','you@email', ['[email protected]'],fail_silently = False)

i have just change it just like that...

 send_mail('Referral Code','This is Your Referral Code','you@email',['[email protected]'],fail_silently = False)

now its working well,probabely the error Reverse for 'send_referral_code' with arguments '()' and keyword arguments '{}' not found is showing because i have put the varible instead of a Simple subject.Since i have put the varible in the place of the subject,thats why its contradicting.