The problem is you are trying to import views from where you have not created it I guess the page is a folder then create the views.py inside of it
On Fri, Oct 16, 2020, 08:10 Salima Begum <[email protected]> wrote: > urls.py > > path('ProductDetails/<int:id>', views.onClickSearch.ProductDetails, > name='ProductDetails'), > > views.py > > > class onClickSearch(): > > def ProductDetails(request, id): > try: > email = request.session.get('email') > proddtls = vk_master_table.objects.filter(id=id).first() > if proddtls: > banners = Extras().bestDeals_cat(proddtls.category_desc) > > # print(banners.product_name) > except Exception as e: > logging.error(e) > return render(request, "ProductDetails.html", {'error': error, > 'form': HomeForm(), > 'time': > settings.SESSION_IDLE_TIMEOUT, > 'name': > first_last_initial(email), > 'msg_count': > msg_count_cl(email), > 'fullname': > fullname(email), 'ProductDetails': proddtls, > 'signinForm': > SigninForm(), 'signupForm': CustomerForm()}) > return render(request, "ProductDetails.html", {'ProductDetails': > proddtls, 'fbanners': banners, > 'form': HomeForm(), > 'signinForm': SigninForm(), > 'name': > first_last_initial(email), > 'msg_count': > msg_count_cl(email), > 'fullname': > fullname(email), > 'time': > settings.SESSION_IDLE_TIMEOUT, > 'signupForm': > CustomerForm()}) > > > > > On Fri, Oct 16, 2020 at 12:32 PM Dhwanil Shah <[email protected]> wrote: > >> Can you post your views.py code >> >> On Fri, 16 Oct 2020 at 12:26, Salima Begum <[email protected]> >> wrote: >> >>> Hi all, >>> vikreya >>> mysite >>> .cache >>> .idea >>> .pytest_cache >>> logs >>> media >>> mysite >>> __init__.py >>> manage.py >>> settings.py >>> urls.py >>> wsgi.py >>> pages >>> .cache >>> migrations >>> static >>> templates >>> tests >>> test_views.py >>> __init__.py >>> admin.py >>> apps.py >>> cron.py >>> Forms.py >>> functions.py >>> models.py >>> urls.py >>> views.py >>> >>> On Fri, Oct 16, 2020 at 12:09 PM Salima Begum < >>> [email protected]> wrote: >>> >>>> Hi @Akinfolarin Stephen, >>>> >>>> >>>> >>>> On Fri, Oct 16, 2020 at 11:10 AM Akinfolarin Stephen < >>>> [email protected]> wrote: >>>> >>>>> First I will like you to tell me the folder where test.py is and >>>>> views.py >>>>> >>>>> On Fri, Oct 16, 2020, 06:27 Salima Begum <[email protected]> >>>>> wrote: >>>>> >>>>>> Hi all, >>>>>> >>>>>> I have written test case for views for details page. Here is below >>>>>> code I have written >>>>>> >>>>>> ``` >>>>>> from django.test import RequestFactory >>>>>> from django.urls import reverse >>>>>> from django.contrib.auth.models import User >>>>>> from pages.models import vk_customer >>>>>> from mixer.backend.django import mixer >>>>>> import pytest >>>>>> >>>>>> from pages.views import ProductDetails >>>>>> >>>>>> >>>>>> @pytest.mark.django_db >>>>>> class TestViews: >>>>>> >>>>>> def test_product_detail_authenticated(self): >>>>>> mixer.blend('pages.vk_master_table') >>>>>> path = reverse('detail', kwargs={'pk': 1516}) >>>>>> request = RequestFactory().get(path) >>>>>> request.user = mixer.blend(vk_customer) >>>>>> >>>>>> response = ProductDetails(request, pk=1516) >>>>>> print(response) >>>>>> assert response.status_code == 200 >>>>>> ``` >>>>>> *This the error i am getting.....* >>>>>> ____________________________________________________________ ERROR >>>>>> collecting pages/tests/test_views.py >>>>>> ____________________________________________________________ >>>>>> ImportError while importing test module >>>>>> 'H:\vikreya\mysite\pages\tests\test_views.py'. >>>>>> Hint: make sure your test modules/packages have valid Python names. >>>>>> Traceback: >>>>>> c:\users\user\appdata\local\programs\python\python38\lib\importlib\__init__.py:127: >>>>>> in import_module >>>>>> return _bootstrap._gcd_import(name[level:], package, level) >>>>>> pages\tests\test_views.py:8: in <module> >>>>>> from pages.views import ProductDetails >>>>>> E ImportError: cannot import name 'ProductDetails' from >>>>>> 'pages.views' (H:\vikreya\mysite\pages\views.py) >>>>>> >>>>>> Please help me out to solve this error, >>>>>> >>>>>> Thank you, >>>>>> ~Salima >>>>>> >>>>>> -- >>>>>> 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 [email protected]. >>>>>> To view this discussion on the web visit >>>>>> https://groups.google.com/d/msgid/django-users/CAMSz6bk187G0NSr%2Bza9RKAFnk475Z8nhxVRF%2BFk4iKtzwLXGxg%40mail.gmail.com >>>>>> <https://groups.google.com/d/msgid/django-users/CAMSz6bk187G0NSr%2Bza9RKAFnk475Z8nhxVRF%2BFk4iKtzwLXGxg%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>>>> . >>>>>> >>>>> -- >>>>> 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 [email protected]. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/django-users/CAFujGLw%3DTZhX-moO6pdp3Ng%3D4LJZ2UQLfE9Y2GmOGsCpxTyVBQ%40mail.gmail.com >>>>> <https://groups.google.com/d/msgid/django-users/CAFujGLw%3DTZhX-moO6pdp3Ng%3D4LJZ2UQLfE9Y2GmOGsCpxTyVBQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> -- >>> 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 [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-users/CAMSz6bm1WKP8qjSzSz5Ouhf%2Bc2K9-pLM4Wc%3DfgSsyUek3KKmqA%40mail.gmail.com >>> <https://groups.google.com/d/msgid/django-users/CAMSz6bm1WKP8qjSzSz5Ouhf%2Bc2K9-pLM4Wc%3DfgSsyUek3KKmqA%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> >> *Dhwanil J Shah* >> *Near Ashok agency, * >> *Madanwad ,* >> >> *Valsad 396001* >> *email:[email protected] <[email protected]> * >> >> -- >> 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 [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAPaScBJhoGY90had%3DdYHGxLTqThmPHR91KzdzW0XohvS06jkUw%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAPaScBJhoGY90had%3DdYHGxLTqThmPHR91KzdzW0XohvS06jkUw%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAMSz6bmkyTCC6izFkPLk9-SiuXYerO-txL84KTsuYAhGC3vJ-w%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAMSz6bmkyTCC6izFkPLk9-SiuXYerO-txL84KTsuYAhGC3vJ-w%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFujGLwB%2BckZYNWry_S-LaLN2ySka2%3D-Zq%3DKD95sUSyDjA1Atw%40mail.gmail.com.

