Re: Help passing the url

2020-04-10 Thread Irfan Khan
Hi,

Need to pass id in function as parameter as well as in that post obj


On Tue, 7 Apr 2020 at 1:23 AM, Luka Nik  wrote:

> How do I pass it exactly?
>
> On Mon, 6 Apr 2020, 9:41 pm ola neat,  wrote:
>
>> You need to add the id as argument in the function
>>
>> On Mon, Apr 6, 2020, 19:17 Luka Nik  wrote:
>>
>>> How can I alter this post_detail function:
>>>
>>>
>>> def post_detail(request):
>>>
>>> post = get_object_or_404(Post)
>>> comments = post.comments.filter(active=True)
>>> new_comment = None
>>> if request.method == 'POST':
>>> comment_form = CommentForm(data=request.POST)
>>> if comment_form.is_valid():
>>> new_comment = comment_form.save(commit=False)
>>> new_comment.post = post
>>> new_comment.save()
>>> else:
>>> comment_form = CommentForm()
>>>
>>> return render(request, 'blog/post_detail.html', {'post': post,
>>>  'comments': comments,
>>>  'new_comment': 
>>> new_comment,
>>>  'comment_form': 
>>> comment_form
>>>  })
>>>
>>>
>>>
>>> So this URL line can read the function?
>>>
>>> path('post//', views.post_detail, name='post-detail'),
>>>
>>>
>>> Note:
>>> In the Post model get_absolute_url is provided for returning the pk
>>>
>>>
>>> Thanks in advance
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAMqindvdzOxxuZSC41Z%3D-TaQianws9jSDvZEevDLTgPw6mFPiw%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAHLKn73Evou6KsXQGFNYA95AXPLjraaP_mXOTeYPsCOAobHY1w%40mail.gmail.com
>> 
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMqindsi%2Be0eRwjST3r68rNUa%2B0qRc%2Behf6%2B8g66im7MUVq8Uw%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKGVirHC%3Dmp3L0UZTeOrPFWug0pfP8_-P_Owsf%3D_KZAtA5xFg%40mail.gmail.com.


Re: Help passing the url

2020-04-06 Thread Luka Nik
How do I pass it exactly?

On Mon, 6 Apr 2020, 9:41 pm ola neat,  wrote:

> You need to add the id as argument in the function
>
> On Mon, Apr 6, 2020, 19:17 Luka Nik  wrote:
>
>> How can I alter this post_detail function:
>>
>>
>> def post_detail(request):
>>
>> post = get_object_or_404(Post)
>> comments = post.comments.filter(active=True)
>> new_comment = None
>> if request.method == 'POST':
>> comment_form = CommentForm(data=request.POST)
>> if comment_form.is_valid():
>> new_comment = comment_form.save(commit=False)
>> new_comment.post = post
>> new_comment.save()
>> else:
>> comment_form = CommentForm()
>>
>> return render(request, 'blog/post_detail.html', {'post': post,
>>  'comments': comments,
>>  'new_comment': 
>> new_comment,
>>  'comment_form': 
>> comment_form
>>  })
>>
>>
>>
>> So this URL line can read the function?
>>
>> path('post//', views.post_detail, name='post-detail'),
>>
>>
>> Note:
>> In the Post model get_absolute_url is provided for returning the pk
>>
>>
>> Thanks in advance
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAMqindvdzOxxuZSC41Z%3D-TaQianws9jSDvZEevDLTgPw6mFPiw%40mail.gmail.com
>> 
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHLKn73Evou6KsXQGFNYA95AXPLjraaP_mXOTeYPsCOAobHY1w%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMqindsi%2Be0eRwjST3r68rNUa%2B0qRc%2Behf6%2B8g66im7MUVq8Uw%40mail.gmail.com.


Re: Help passing the url

2020-04-06 Thread ola neat
You need to add the id as argument in the function

On Mon, Apr 6, 2020, 19:17 Luka Nik  wrote:

> How can I alter this post_detail function:
>
>
> def post_detail(request):
>
> post = get_object_or_404(Post)
> comments = post.comments.filter(active=True)
> new_comment = None
> if request.method == 'POST':
> comment_form = CommentForm(data=request.POST)
> if comment_form.is_valid():
> new_comment = comment_form.save(commit=False)
> new_comment.post = post
> new_comment.save()
> else:
> comment_form = CommentForm()
>
> return render(request, 'blog/post_detail.html', {'post': post,
>  'comments': comments,
>  'new_comment': 
> new_comment,
>  'comment_form': 
> comment_form
>  })
>
>
>
> So this URL line can read the function?
>
> path('post//', views.post_detail, name='post-detail'),
>
>
> Note:
> In the Post model get_absolute_url is provided for returning the pk
>
>
> Thanks in advance
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMqindvdzOxxuZSC41Z%3D-TaQianws9jSDvZEevDLTgPw6mFPiw%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHLKn73Evou6KsXQGFNYA95AXPLjraaP_mXOTeYPsCOAobHY1w%40mail.gmail.com.


Help passing the url

2020-04-06 Thread Luka Nik
How can I alter this post_detail function:


def post_detail(request):

post = get_object_or_404(Post)
comments = post.comments.filter(active=True)
new_comment = None
if request.method == 'POST':
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
new_comment = comment_form.save(commit=False)
new_comment.post = post
new_comment.save()
else:
comment_form = CommentForm()

return render(request, 'blog/post_detail.html', {'post': post,
 'comments': comments,
 'new_comment': new_comment,
 'comment_form':
comment_form
 })



So this URL line can read the function?

path('post//', views.post_detail, name='post-detail'),


Note:
In the Post model get_absolute_url is provided for returning the pk


Thanks in advance

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMqindvdzOxxuZSC41Z%3D-TaQianws9jSDvZEevDLTgPw6mFPiw%40mail.gmail.com.


Re: passing '&' in url

2012-02-28 Thread Tom Evans
On Tue, Feb 28, 2012 at 11:13 AM, vijay shanker  wrote:
> i need to pass " & " as query e.g q=larsen & turbo
> urlencode does not works as finally its as good as without it for
> above eg.
> please suggest.
>

>>> from django.http import QueryDict
>>> qstring = QueryDict('', mutable=True)
>>> qstring['query'] = 'hello'
>>> qstring.urlencode()
'query=hello%26goodbye'

Cheers

Tom

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



passing '&' in url

2012-02-28 Thread vijay shanker
i need to pass " & " as query e.g q=larsen & turbo
urlencode does not works as finally its as good as without it for
above eg.
please suggest.

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



Re: Passing optional URL params to reverse() function

2009-08-11 Thread nabucosound

Hi Malcolm,

Thanks for your answer. Somehow I had a shortcircuit in my brain
yerterday that made me try to do an impossible upon the framework,
that is, using the same GET response with the same URL after an HTTP
redirect, rendering extra information if extra params in the URLconf
url were given. I finally realized that this was just impossible --
the one and only ways to pass info into an HTTP request is via GET or
POST params, or extra HEADers -- but anyway I am a passionate spirit
and sometimes I am blinded.

H.

On Aug 11, 3:41 am, Malcolm Tredinnick 
wrote:
> On Mon, 2009-08-10 at 11:28 -0700, nabucosound wrote:
> > Hi all:
>
> > I have a URLconf url entry like this:
>
> > url(
> >         regex=r'^(?P\w+)/(?P[-\w]+)/$',
> >         view='show_post',
> >         name='show_post',
> >         kwargs={'msg': None},
> >     ),
>
> > and I want to call it with HttpResponseRedirect and reverse():
>
> > filters = {'category': post.category.name, 'slug': post.slug}
> > return HttpResponseRedirect(reverse('show_post', kwargs=filters))
>
> > but I am getting this error:
>
> > NoReverseMatch at /commentposted/first-post/
>
> > Reverse for 'show_post' with arguments '()' and keyword arguments
> > '{'category': u'django', 'msg': 'Your comment has been posted',
> > 'slug': u'first-post'}' not found.
>
> [...]
>
> > Is there any way to pass th reverse() function extra optional
> > parameters that the url define? Or am I crazy?
>
> No, you can't do that. By the way, the extra arguments you are passing
> in aren't *optional* -- they are simply not required. There is not
> situation in which they will be used to construct the URL.
>
> You can only pass in parameters that are present in the URL pattern.
> There are a bunch of technical reasons for this (including handling
> optional arguments and precise error reporting), so it's not an
> arbitrary decision.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Passing optional URL params to reverse() function

2009-08-10 Thread Malcolm Tredinnick

On Mon, 2009-08-10 at 11:28 -0700, nabucosound wrote:
> Hi all:
> 
> I have a URLconf url entry like this:
> 
> 
> url(
> regex=r'^(?P\w+)/(?P[-\w]+)/$',
> view='show_post',
> name='show_post',
> kwargs={'msg': None},
> ),
> 
> 
> and I want to call it with HttpResponseRedirect and reverse():
> 
> 
> filters = {'category': post.category.name, 'slug': post.slug}
> return HttpResponseRedirect(reverse('show_post', kwargs=filters))
> 
> 
> but I am getting this error:
> 
> 
> NoReverseMatch at /commentposted/first-post/
> 
> Reverse for 'show_post' with arguments '()' and keyword arguments
> '{'category': u'django', 'msg': 'Your comment has been posted',
> 'slug': u'first-post'}' not found.
> 

[...]
> Is there any way to pass th reverse() function extra optional
> parameters that the url define? Or am I crazy?

No, you can't do that. By the way, the extra arguments you are passing
in aren't *optional* -- they are simply not required. There is not
situation in which they will be used to construct the URL.

You can only pass in parameters that are present in the URL pattern.
There are a bunch of technical reasons for this (including handling
optional arguments and precise error reporting), so it's not an
arbitrary decision.

Regards,
Malcolm



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



Passing optional URL params to reverse() function

2009-08-10 Thread nabucosound

Hi all:

I have a URLconf url entry like this:

url(
regex=r'^(?P\w+)/(?P[-\w]+)/$',
view='show_post',
name='show_post',
kwargs={'msg': None},
),

and I want to call it with HttpResponseRedirect and reverse():

filters = {'category': post.category.name, 'slug': post.slug, 'msg':
msg}
return HttpResponseRedirect(reverse('show_post', kwargs=filters))

but I am getting this error:

NoReverseMatch at /commentposted/first-post/

Reverse for 'show_post' with arguments '()' and keyword arguments
'{'category': u'django', 'msg': 'Your comment has been posted',
'slug': u'first-post'}' not found.

Request Method: GET
Request URL:http://localhost:8000/commentposted/first-post/?c=8
Exception Type: NoReverseMatch
Exception Value:

Reverse for 'show_post' with arguments '()' and keyword arguments
'{'category': u'django', 'msg': 'Your comment has been posted',
'slug': u'first-post'}' not found.

Is there any way to pass th reverse() function extra optional
parameters that the url define (msg param in this case)? Or am I
crazy?

Thanks in advance!

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



Passing optional URL params to reverse() function

2009-08-10 Thread nabucosound

Hi all:

I have a URLconf url entry like this:


url(
regex=r'^(?P\w+)/(?P[-\w]+)/$',
view='show_post',
name='show_post',
kwargs={'msg': None},
),


and I want to call it with HttpResponseRedirect and reverse():


filters = {'category': post.category.name, 'slug': post.slug}
return HttpResponseRedirect(reverse('show_post', kwargs=filters))


but I am getting this error:


NoReverseMatch at /commentposted/first-post/

Reverse for 'show_post' with arguments '()' and keyword arguments
'{'category': u'django', 'msg': 'Your comment has been posted',
'slug': u'first-post'}' not found.

Request Method: GET
Request URL:http://localhost:8000/commentposted/first-post/?c=8
Exception Type: NoReverseMatch
Exception Value:

Reverse for 'show_post' with arguments '()' and keyword arguments
'{'category': u'django', 'msg': 'Your comment has been posted',
'slug': u'first-post'}' not found.


Is there any way to pass th reverse() function extra optional
parameters that the url define? Or am I crazy?

Thanks in advance!

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