Tuesday, April 21, 2015

Re: Difficulty in passing positional arguments in url !!!

I think that it is the question mark in your url pattern that is causing the problem.  In a real url, question mark separates the path from the query parameters.  Parentheses in url patterns are for capturing parts of the path, and are not associated with query parameters.  Just leave out the ? and it may just work.

(Of course, if you also want this parameter filled in by the submission of a form, you would be better to put the email address in a query paramater, as a form submission would.)

On Tue, Apr 21, 2015 at 3:25 PM, livelikehimanshu12 <livelikehimanshu12@gmail.com> wrote:
Hello friends ,
I am trying to send a simple parameter to view from my template .
But i am getting the error 'Reverse for acceptfriend with arguments ('hpenvy@hp.com',) and keyword arguments {} not found. 
Plzz help me !! I am not much comfortable with url concepts !!
----> i need to pass hpenvy@hp.com to my view !!

###################################################### url.py ##############################################################
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static

admin.autodiscover()


urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    
url(r'^$', 'app.views.home',name='homeurl'),
    url(r'^signup/$','app.views.signup',name='signupurl'),
    url(r'^verifylogin/$','app.views.loginverify',name='verifyloginurl'),
    url(r'^verifysignup/$','app.views.signupverify',name='verifysignupurl'),
    url(r'^login/$','app.views.login',name='loginurl'),
   # url(r'^imgurl/$','app.views.imageviewer',name='imgurl'),
    url(r'^uploadpic/$','app.views.uploadpic',name='uploadpic'),
    url(r'^refreshpage/$','app.views.refreshpage',name='refreshpage'),
    url(r'^acceptfriend/?(\w+)/$', 'app.views.acceptfriend','acceptfriend'),
)+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
 
###################################################### profile.html (my template )##################################################################
..
..
..{% for g in list_reqfromemail %}
                                            <tr>
                                               <td> <a href="{% url 'acceptfriend' g %}">{{ g }} </a></td>
                                                
                                            </tr>
                                        {% endfor %}
#################################################### views.py ################################################################################
def acceptfriend(request,reqfromemail):
    try:
        myemail=request.session['email']
        print("\n\n",request,"\n\n",myemail,"\n\n",reqfromemail)
        return render(request,'success.html',{"message":"congrats","name":myemail})
    except:
        return render(request,'error.html',{"error":"It is not working !!!"})

###########################################################################################################################################
If i remove the  href line from my template ,profile.html then my app runs normally !!
So obviously there is some mistake that i am doing while using href ,or sending url parameters or  in extracting it. Also what is the use of reverse() in django i read the documentation but i am unable to understand it !!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f300d565-d747-46a4-b685-2c1df8bb2d19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAB%2BAj0s2bQxBnLXyThY8ADopf2iKDFJ4DbPRqiaJY8bXkndjhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment