a variable is not defined

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

a variable is not defined

sotiris moustogiannis
I have an error: name 'result' is not defined


def search(request):

   
def get_queryset(self):
        query
= self.request.GET.get('q')
        result
= Shops.objects.filter(Q(city=query))

       
return result
   
    context
={
       
'shops' : result,
   
}

   
return render(request, 'booking/search.html',context)





--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: a variable is not defined

wd-3
Dude, you need to indent at the line include 'context' ... it's a beginners  problem...

On Fri, Oct 18, 2019 at 10:14 AM sotiris moustogiannis <[hidden email]> wrote:
I have an error: name 'result' is not defined


def search(request):

   
def get_queryset(self):
        query
= self.request.GET.get('q')
        result
= Shops.objects.filter(Q(city=query))

       
return result
   
    context
={
       
'shops' : result,
   
}

   
return render(request, 'booking/search.html',context)





--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABexzmgqw2NisRErdRZqXeat9T%3D8FvkBsueybE%2BTvuYEMzkOfw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: a variable is not defined

wd-3
oh ,sorry my mistake. But I think the error is pretty clear ...

On Fri, Oct 18, 2019 at 10:23 AM wd <[hidden email]> wrote:
Dude, you need to indent at the line include 'context' ... it's a beginners  problem...

On Fri, Oct 18, 2019 at 10:14 AM sotiris moustogiannis <[hidden email]> wrote:
I have an error: name 'result' is not defined


def search(request):

   
def get_queryset(self):
        query
= self.request.GET.get('q')
        result
= Shops.objects.filter(Q(city=query))

       
return result
   
    context
={
       
'shops' : result,
   
}

   
return render(request, 'booking/search.html',context)





--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: a variable is not defined

Jorge Gimeno
wd,

The problem here is that when you're creating the context, the name 'result' is not defined. When the get_queryset() method returns, the result name goes out of scope.  My guess that's why you're getting a NameError.

If that's not it, I would suggest cutting and pasting the traceback and showing us the actual code (with line numbers if you have them). It will help us diagnose the problem.

-Jorge

On Thu, Oct 17, 2019 at 7:25 PM wd <[hidden email]> wrote:
oh ,sorry my mistake. But I think the error is pretty clear ...

On Fri, Oct 18, 2019 at 10:23 AM wd <[hidden email]> wrote:
Dude, you need to indent at the line include 'context' ... it's a beginners  problem...

On Fri, Oct 18, 2019 at 10:14 AM sotiris moustogiannis <[hidden email]> wrote:
I have an error: name 'result' is not defined


def search(request):

   
def get_queryset(self):
        query
= self.request.GET.get('q')
        result
= Shops.objects.filter(Q(city=query))

       
return result
   
    context
={
       
'shops' : result,
   
}

   
return render(request, 'booking/search.html',context)





--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANfN%3DK_7-xzLEYw%3DR8-NF5De%3D7H79O%3D0NXUkk_u26ZmZm8-iZw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: a variable is not defined

sotiris moustogiannis
I read that you can't use the def get_queryset into a function but only in a generic class view, so maybe the def get_queryset function does not run. I want to  make my own custom function and i want to find a way to get self parameter in my function. Thanks a lot.

On Friday, October 18, 2019 at 5:49:48 AM UTC+3, jlgimeno71 wrote:
wd,

The problem here is that when you're creating the context, the name 'result' is not defined. When the get_queryset() method returns, the result name goes out of scope.  My guess that's why you're getting a NameError.

If that's not it, I would suggest cutting and pasting the traceback and showing us the actual code (with line numbers if you have them). It will help us diagnose the problem.

-Jorge

On Thu, Oct 17, 2019 at 7:25 PM wd <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="NuWYdRdlDwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">w...@...> wrote:
oh ,sorry my mistake. But I think the error is pretty clear ...

On Fri, Oct 18, 2019 at 10:23 AM wd <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="NuWYdRdlDwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">w...@...> wrote:
Dude, you need to indent at the line include 'context' ... it's a beginners  problem...

On Fri, Oct 18, 2019 at 10:14 AM sotiris moustogiannis <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="NuWYdRdlDwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">soto...@...> wrote:
I have an error: name 'result' is not defined


def search(request):

   
def get_queryset(self):
        query
= self.request.GET.get('q')
        result
= Shops.objects.filter(Q(city=query))

       
return result
   
    context
={
       
'shops' : result,
   
}

   
return render(request, 'booking/search.html',context)





--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="NuWYdRdlDwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="NuWYdRdlDwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%40mail.gmail.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/24be404f-1dd8-4532-ab55-52e069e2e2c9%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: a variable is not defined

sotiris moustogiannis
I want to make custom function because i want to take one result from 2 different models (inner join), and i dont find a way to use 2 models in my listview class (generic)

On Friday, October 18, 2019 at 6:03:18 AM UTC+3, sotiris moustogiannis wrote:
I read that you can't use the def get_queryset into a function but only in a generic class view, so maybe the def get_queryset function does not run. I want to  make my own custom function and i want to find a way to get self parameter in my function. Thanks a lot.

On Friday, October 18, 2019 at 5:49:48 AM UTC+3, jlgimeno71 wrote:
wd,

The problem here is that when you're creating the context, the name 'result' is not defined. When the get_queryset() method returns, the result name goes out of scope.  My guess that's why you're getting a NameError.

If that's not it, I would suggest cutting and pasting the traceback and showing us the actual code (with line numbers if you have them). It will help us diagnose the problem.

-Jorge

On Thu, Oct 17, 2019 at 7:25 PM wd <[hidden email]> wrote:
oh ,sorry my mistake. But I think the error is pretty clear ...

On Fri, Oct 18, 2019 at 10:23 AM wd <[hidden email]> wrote:
Dude, you need to indent at the line include 'context' ... it's a beginners  problem...

On Fri, Oct 18, 2019 at 10:14 AM sotiris moustogiannis <[hidden email]> wrote:
I have an error: name 'result' is not defined


def search(request):

   
def get_queryset(self):
        query
= self.request.GET.get('q')
        result
= Shops.objects.filter(Q(city=query))

       
return result
   
    context
={
       
'shops' : result,
   
}

   
return render(request, 'booking/search.html',context)





--
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 [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.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 [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%40mail.gmail.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dcd65a19-628b-4ac9-9f60-d8d4b726d945%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: a variable is not defined

Jorge Gimeno

On Thu, Oct 17, 2019 at 8:14 PM sotiris moustogiannis <[hidden email]> wrote:
I want to make custom function because i want to take one result from 2 different models (inner join), and i dont find a way to use 2 models in my listview class (generic)

On Friday, October 18, 2019 at 6:03:18 AM UTC+3, sotiris moustogiannis wrote:
I read that you can't use the def get_queryset into a function but only in a generic class view, so maybe the def get_queryset function does not run. I want to  make my own custom function and i want to find a way to get self parameter in my function. Thanks a lot.

On Friday, October 18, 2019 at 5:49:48 AM UTC+3, jlgimeno71 wrote:
wd,

The problem here is that when you're creating the context, the name 'result' is not defined. When the get_queryset() method returns, the result name goes out of scope.  My guess that's why you're getting a NameError.

If that's not it, I would suggest cutting and pasting the traceback and showing us the actual code (with line numbers if you have them). It will help us diagnose the problem.

-Jorge

On Thu, Oct 17, 2019 at 7:25 PM wd <[hidden email]> wrote:
oh ,sorry my mistake. But I think the error is pretty clear ...

On Fri, Oct 18, 2019 at 10:23 AM wd <[hidden email]> wrote:
Dude, you need to indent at the line include 'context' ... it's a beginners  problem...

On Fri, Oct 18, 2019 at 10:14 AM sotiris moustogiannis <[hidden email]> wrote:
I have an error: name 'result' is not defined


def search(request):

   
def get_queryset(self):
        query
= self.request.GET.get('q')
        result
= Shops.objects.filter(Q(city=query))

       
return result
   
    context
={
       
'shops' : result,
   
}

   
return render(request, 'booking/search.html',context)





--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dcd65a19-628b-4ac9-9f60-d8d4b726d945%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANfN%3DK8jvtCjxRvirOmgT7p_GQdr9Lm23B40NJ6QkO_kaGTNYA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: a variable is not defined

sotiris moustogiannis
thanks for your help!!

On Friday, October 18, 2019 at 6:59:05 AM UTC+3, jlgimeno71 wrote:
I saw this that may be relevant:

<a href="https://stackoverflow.com/questions/7576202/how-can-i-pass-two-models-to-a-class-based-generic-view" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F7576202%2Fhow-can-i-pass-two-models-to-a-class-based-generic-view\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGrLawQ8hlVcouC8C6uTcSac9XAyQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F7576202%2Fhow-can-i-pass-two-models-to-a-class-based-generic-view\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGrLawQ8hlVcouC8C6uTcSac9XAyQ&#39;;return true;">https://stackoverflow.com/questions/7576202/how-can-i-pass-two-models-to-a-class-based-generic-view

-Jorge

On Thu, Oct 17, 2019 at 8:14 PM sotiris moustogiannis <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="zpl0dt9oDwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">soto...@...> wrote:
I want to make custom function because i want to take one result from 2 different models (inner join), and i dont find a way to use 2 models in my listview class (generic)

On Friday, October 18, 2019 at 6:03:18 AM UTC+3, sotiris moustogiannis wrote:
I read that you can't use the def get_queryset into a function but only in a generic class view, so maybe the def get_queryset function does not run. I want to  make my own custom function and i want to find a way to get self parameter in my function. Thanks a lot.

On Friday, October 18, 2019 at 5:49:48 AM UTC+3, jlgimeno71 wrote:
wd,

The problem here is that when you're creating the context, the name 'result' is not defined. When the get_queryset() method returns, the result name goes out of scope.  My guess that's why you're getting a NameError.

If that's not it, I would suggest cutting and pasting the traceback and showing us the actual code (with line numbers if you have them). It will help us diagnose the problem.

-Jorge

On Thu, Oct 17, 2019 at 7:25 PM wd <[hidden email]> wrote:
oh ,sorry my mistake. But I think the error is pretty clear ...

On Fri, Oct 18, 2019 at 10:23 AM wd <[hidden email]> wrote:
Dude, you need to indent at the line include 'context' ... it's a beginners  problem...

On Fri, Oct 18, 2019 at 10:14 AM sotiris moustogiannis <[hidden email]> wrote:
I have an error: name 'result' is not defined


def search(request):

   
def get_queryset(self):
        query
= self.request.GET.get('q')
        result
= Shops.objects.filter(Q(city=query))

       
return result
   
    context
={
       
'shops' : result,
   
}

   
return render(request, 'booking/search.html',context)





--
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 [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.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 [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%40mail.gmail.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="zpl0dt9oDwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/dcd65a19-628b-4ac9-9f60-d8d4b726d945%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/dcd65a19-628b-4ac9-9f60-d8d4b726d945%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/dcd65a19-628b-4ac9-9f60-d8d4b726d945%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/dcd65a19-628b-4ac9-9f60-d8d4b726d945%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c602853d-b5c7-4105-b77c-95ed37ac67ea%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: a variable is not defined

Joalbert Palacios
Not sure, but I believe that is because scope, given that result variable is defined in the inner method and not defined in search function.

On Fri, Oct 18, 2019, 3:49 PM sotiris moustogiannis <[hidden email]> wrote:
thanks for your help!!

On Friday, October 18, 2019 at 6:59:05 AM UTC+3, jlgimeno71 wrote:

On Thu, Oct 17, 2019 at 8:14 PM sotiris moustogiannis <[hidden email]> wrote:
I want to make custom function because i want to take one result from 2 different models (inner join), and i dont find a way to use 2 models in my listview class (generic)

On Friday, October 18, 2019 at 6:03:18 AM UTC+3, sotiris moustogiannis wrote:
I read that you can't use the def get_queryset into a function but only in a generic class view, so maybe the def get_queryset function does not run. I want to  make my own custom function and i want to find a way to get self parameter in my function. Thanks a lot.

On Friday, October 18, 2019 at 5:49:48 AM UTC+3, jlgimeno71 wrote:
wd,

The problem here is that when you're creating the context, the name 'result' is not defined. When the get_queryset() method returns, the result name goes out of scope.  My guess that's why you're getting a NameError.

If that's not it, I would suggest cutting and pasting the traceback and showing us the actual code (with line numbers if you have them). It will help us diagnose the problem.

-Jorge

On Thu, Oct 17, 2019 at 7:25 PM wd <[hidden email]> wrote:
oh ,sorry my mistake. But I think the error is pretty clear ...

On Fri, Oct 18, 2019 at 10:23 AM wd <[hidden email]> wrote:
Dude, you need to indent at the line include 'context' ... it's a beginners  problem...

On Fri, Oct 18, 2019 at 10:14 AM sotiris moustogiannis <[hidden email]> wrote:
I have an error: name 'result' is not defined


def search(request):

   
def get_queryset(self):
        query
= self.request.GET.get('q')
        result
= Shops.objects.filter(Q(city=query))

       
return result
   
    context
={
       
'shops' : result,
   
}

   
return render(request, 'booking/search.html',context)





--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/543debc7-d517-4a7a-a9b8-f3fc7c7cc60d%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABexzmhZtCXQRWB7S%3DL8S3B2rzmnbi3Raan1MFKW1asbSoShqg%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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dcd65a19-628b-4ac9-9f60-d8d4b726d945%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c602853d-b5c7-4105-b77c-95ed37ac67ea%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEtK16E9qJ-xDCWTRr7vAb0XL%2B59Punr33P3w6RnjDm46-FYNg%40mail.gmail.com.