Re: how to make docker image of your django app

2020-06-17 Thread onlinejudge95
On Wed, Jun 17, 2020 at 7:28 PM Jason Turner  wrote:

>
> https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/
>
> Also, Will Vincent's book "Django for Professionals" is a good resource.
>
> On Wed, Jun 17, 2020, 8:51 AM Anirudh choudhary <
> anirudhchoudary...@gmail.com> wrote:
>
>> I Want to make make a docker image of my Django app using PostgreSQL and
>> unicorn. but I can't find any good tutorial for reference
>> please share my link to if you know any good tutorial
>>
> The first philosophy of docker is to run a single service in a container,
which would translate to you running 2 containers.

   1. Django container having all your Django code
   2. DB container having your DB

Now you can(i would say must) leverage *docker-compose* for local
development. It's somewhat easy to learn, just follow along with the
official docs .

> My Dockerfile now is like
>> FROM python:3.6
>> ENV PYTHONUNBUFFERED 1
>> RUN mkdir /app
>> WORKDIR /app
>> COPY requirements.txt /app/requirements.txt
>> RUN pip install -r requirements.txt
>> RUN apt install postgresql-client
>> RUN mkdir postgresqlcode
>> COPY /private_key/client-cert.pem /private_key/client-cert.pem
>> COPY /private_key/client-cert.pem /private_key/client-cert.pem
>> COPY /private_key/client-cert.pem /private_key/client-cert.pem
>> RUN psql "sslmode=verify-ca sslrootcert=\server-ca.pem \
>> sslcert=client-cert.pem sslkey=\client-key.pem \
>> hostaddr=hostaddress \
>> port=port \
>> user=postgres dbname=postgres"
>> COPY . /code/
>>
>>
>> I know I have to make Django-compose.yml file and I ha
>>
>>
>>
>>
>>
>>
>>
>> --
>> 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/CAL8_rkEBoEuAC7N9XCgDsakOVSsGtM1EM_3bZc9azOL3jPhDjw%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/CADoyC14A%3Df_c7FGt8RQqacpYKMuQAkj-QmGA49Hmzr08EaorLw%40mail.gmail.com
> 
> .
>


-- 
Thanks,
Mayank Pathak

-- 
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/CAD%3DM5eQcWT7OvuU-cGASF8_fLdgfmoxWGxQRU%2BX09gucSBhn_Q%40mail.gmail.com.


Re: understanding urls, forms, and HTTP ERROR 405

2020-02-21 Thread onlinejudge95
On Fri, Feb 21, 2020 at 2:24 AM Phil Kauffman 
wrote:

> So something like this?
>
Yes if you are using method based views. You can still do the same using
class-based views by referring to the following
https://stackoverflow.com/questions/15622354/django-listview-with-post-method


> def site(request, site_id):
> site = get_object_or_404(Site.name, pk=site_id)
>
> def sitesubmit(request):
> #site=get_object_or_404(Site, pk=site_id)
> form = SelectSite()
> if request.method == 'POST':
> form = SelectSite(request.POST)
> if form.is_valid():
> instance = form.save(commit=False)
> instance.name = site.site_id
> instance.save()
> else:
> form = SelectSite()
> return render(request, 'app/home.html', {'form': form})
>
> I'm just learning this stuff. If you can think of any posts or examples
> please let me know.
>
> On Thursday, February 20, 2020 at 1:16:07 PM UTC-5, OnlineJudge95 wrote:
>
>>
>>
>> On Thu, Feb 20, 2020 at 11:38 PM Phil Kauffman 
>> wrote:
>>
>>> Hello,
>>>
>>> Newbie in need of a little shove. It seems I need to review the purpose
>>> of the urls.py file. At present I am getting an HTTP Error 405 with the
>>> following:
>>>
>> HTTP 405 error code states the the HTTP method is not allowed on the
>> endpoint (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405)
>>
>>>
>>> urls.py:
>>> path('', views.show_site, name = 'home'),
>>> path('site-view', views.List.as_view(), name='site-view')
>>>
>>> views.py
>>> class List(ListView):
>>> def get_queryset(self, *args, **kwargs):
>>> return Profile.objects.filter(sitename_id=self.kwargs['pk'])
>>>
>> You need to define the post() method yourself,
>>
>>>
>>> def show_site(request):
>>> form = SelectSite()
>>> if request.method == 'POST':
>>> form = SelectSite(request.POST)
>>> if form.is_valid():
>>> pass
>>> else:
>>> form = SelectSite()
>>> return render(request, 'app/home.html', {'form': form})
>>>
>>> home.html
>>> {% extends 'app\base.html' %}
>>>
>>> {% block title %}Site Home{% endblock %}
>>> {% block content %}
>>> This Form is Terrible
>>> {% csrf_token %}
>>>  {{form}} 
>>> 
>>> 
>>> {% endblock %}
>>>
>>> Any guidance would be greatly appreciated.
>>>
>>> Thank You
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/10be0e68-da3f-42cd-a095-96d6d2a5617f%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/10be0e68-da3f-42cd-a095-96d6d2a5617f%40googlegroups.com?utm_medium=email_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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ba1394b9-1fde-442e-9d4d-e67e32b2f694%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/ba1394b9-1fde-442e-9d4d-e67e32b2f694%40googlegroups.com?utm_medium=email_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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eQvbc--tMz%2BgnjW%3DydudFxivOajJoz6MgDDRHKCmRxAuA%40mail.gmail.com.


Re: understanding urls, forms, and HTTP ERROR 405

2020-02-20 Thread onlinejudge95
On Thu, Feb 20, 2020 at 11:38 PM Phil Kauffman 
wrote:

> Hello,
>
> Newbie in need of a little shove. It seems I need to review the purpose of
> the urls.py file. At present I am getting an HTTP Error 405 with the
> following:
>
HTTP 405 error code states the the HTTP method is not allowed on the
endpoint (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405)

>
> urls.py:
> path('', views.show_site, name = 'home'),
> path('site-view', views.List.as_view(), name='site-view')
>
> views.py
> class List(ListView):
> def get_queryset(self, *args, **kwargs):
> return Profile.objects.filter(sitename_id=self.kwargs['pk'])
>
You need to define the post() method yourself,

>
> def show_site(request):
> form = SelectSite()
> if request.method == 'POST':
> form = SelectSite(request.POST)
> if form.is_valid():
> pass
> else:
> form = SelectSite()
> return render(request, 'app/home.html', {'form': form})
>
> home.html
> {% extends 'app\base.html' %}
>
> {% block title %}Site Home{% endblock %}
> {% block content %}
> This Form is Terrible
> {% csrf_token %}
>  {{form}} 
> 
> 
> {% endblock %}
>
> Any guidance would be greatly appreciated.
>
> Thank You
>
> --
> 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/10be0e68-da3f-42cd-a095-96d6d2a5617f%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eRtsXUhGdjNvmMCjtBeG6OyQmJcwG3tjDyzfQ_GmX_pvQ%40mail.gmail.com.


Re: Django rest framework error

2020-02-20 Thread onlinejudge95
On Thu, Feb 20, 2020 at 11:30 PM Soumen Khatua 
wrote:

> If I'm using serializer then it's working fine but I want to return only
> database object. So for that Do I need to add serializer.
>
You do have to serialize your responses, you just can't send Python objects
as an HTTP response, think about the content-type of your requests

> Thank you for your response.
>
> On Thu 20 Feb, 2020, 11:17 PM MTS BOUR,  wrote:
>
>> Can you show us your serializer.py file?
>>
>>
>> Le jeu. 20 févr. 2020 17:40, Soumen Khatua  a
>> écrit :
>>
>>> Hi Folks,
>>>
>>> I'm getting this error, I don't know how to solve it:
>>>
>>>
>>>
>>>
>>> *File
>>> "C:\Users\TildeHat\AppData\Local\Programs\Python\Python38-32\lib\json\encoder.py",
>>> line 179, in defaultraise TypeError(f'Object of type
>>> {o.__class__.__name__} 'TypeError: Object of type User is not JSON
>>> serializable*
>>>
>>>
>>> *This is my code:*
>>>
>>> *Views.py:*
>>> *--*
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *class LocationApiView(APIView):permission_classes =
>>> (IsAuthenticated,)def get(self,request,format=None):user =
>>> request.useruser_location = Profile.objects.get(user = user)
>>> return Response({'user':user}, status = status.HTTP_200_OK)*
>>>
>>>
>>> *urls.py*
>>> **
>>>
>>>
>>>
>>>
>>> *urlpatterns = [
>>> path('api/location/',views.LocationApiView.as_view(),name =
>>> 'api_location')]*
>>>
>>>
>>> *btw when I'm sending a normal message it's working fine. But in this
>>> case I'm getting this error.*
>>>
>>> *Thank You*
>>>
>>> *Regards,*
>>>
>>> *Soumen*
>>>
>>> --
>>> 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/CAPUw6WZh%2BgVfi7URo8vPbpjYfT%3D5AdjGyhntBMLgiZ1msiZECg%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/CAAq3G-Ea6aEgo9ECrkbe2Y0bXWGG-GVb-utLf%2B7bn9RCGZ0fGw%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/CAPUw6WbZ%2BOYqcEpadaxCz_9z45dDpbLRduLuUsgGAg2DyPnhFQ%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/CAD%3DM5eRXuVv2G-Ld17wydJzPybPo_ccQyoa%2BkQhB4k3nV%3Dz0KQ%40mail.gmail.com.


Re: Bootstrap Nav Bar

2020-02-20 Thread onlinejudge95
On Thu, Feb 20, 2020 at 8:24 PM Perceval Maturure 
wrote:

> Dear all
> I need help with making a bootstrap Nav bar which populates menus
> restricted to a certain width of the nav bar
>
> Any pointers?
>
Maybe ask on a bootstrap mailing list

> Regards
>
> --
> 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/8681CE86-0F43-4B7A-B032-05285635D68C%40gmail.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/CAD%3DM5eT9YdzH_4ZgEJsLStYMpQY8r3B2Hf849rBh%3Dst99NCyOQ%40mail.gmail.com.


Re: Django User Roles and user relations

2020-02-20 Thread onlinejudge95
On Thu, Feb 20, 2020 at 5:53 PM Kirankumar 
wrote:

> Hii All..
>
>   I'm trying to give level roles like admin defaultly it is
> available and Manager group and normal user groups in my django
> aplication...
>
>   Generally admin can fetch all the records created by all
> users..Now my requirement is the user which is in manager group can fetch
> their own records and his subordinate (normal) user's records...I have no
> idea to develop this scenario how to relate normal users to particular
> associate (Manager) user...
>
Looks like a One(Manager)-To-Many(Subordinates) Relationship would make
sense here

>
>  Can anyone please help me out..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/18e43f77-8a33-4c7a-80ec-5151d10a5e96%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eTdaHwBxBd8BC_kyfB_JHjw%3D-u%2BZwXpQvrJ_ApRfvEZDg%40mail.gmail.com.


Re: Retaining text in search input boxes

2020-02-20 Thread onlinejudge95
+1

On Thu, Feb 20, 2020 at 4:25 PM Farai M  wrote:

> For drop downs use JavaScript script or JQuery to set the value of the
> value of the selected item.For input use an if on the value if it's
> populated then the input value is equal to the attribute us you put it
> .Another option is to use the default on attribute but make it an empty
> string so you don't have none when attribute is empty .
>
> On Thu, Feb 20, 2020, 12:14 PM Dick Arnold  wrote:
>
>> I used a value of {{attribute value}}.  so it is nor a fixed value, but
>> is the value submitted.  Doesn't work well for drop down input fields.
>> still researching.
>>
>> On Saturday, February 15, 2020 at 12:50:59 PM UTC-6, Dick Arnold wrote:
>>>
>>> I have a personnel database which has to be edited to keep it current.
>>> I have created search parameters to find the person to edit.
>>> The exact name of the person is not always known, therefore the name
>>> field for searching can contain only a few of the characters.  This can
>>> create a list of several people.
>>> After the search parameters are entered a "Search" button is clicked and
>>> the output, if any, is displayed in a table.
>>> If the search parameters need to be improved, I want the original
>>> (current) search argument to be retained in the argument field so I do not
>>> need to re-type ALL the search parameters, just the ones I want to change.
>>>
>>> I have not been able to find a way to retain the value in the search
>>> input box,
>>>
>>> Does anyone know how to accomplish this?
>>>
>>> Here's the input for one of the input boxes.
>>>
>>> 
>>>
>> --
>> 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/77088a26-742b-4bb4-8f2f-b74c5375119d%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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMeub5MC4smYxE%2BJjksURBP0aEWtCN%3DTf0-ZeDh8AgmdLy42eg%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/CAD%3DM5eS77KgQL8eB1sp%3DZKLMUCjkfXGE0_fe0d5b%2BDKHZhdJpQ%40mail.gmail.com.


Re: Re: I am filling up the form but my filled out items are not rendering into database and also the session is not working

2020-02-19 Thread onlinejudge95
On Wed, Feb 19, 2020 at 11:31 PM  wrote:

> The template file
>
>
>
>
>
> <*form **method**="post" **novalidate*>
>
> No action attribute defined here. Where do you expect the data to be sent?

>
> {% csrf_token %}
>
>   <*div **class**="form-group col-md-4 mb-0"*>
> {{ form.name|as_crispy_field }}
>   
>   <*div **class**="form-group col-md-4 mb-0"*>
> {{ form.email|as_crispy_field }}
>   
>   <*div **class**="form-group col-md-4 mb-0"*>
> {{ form.link_sent|as_crispy_field }}
>   
> <*button **type**="submit" **class**="btn btn-primary"*>Start
>  <*button **type**="submit" **class**="btn btn-primary"*>Save
>
>   
> {% endblock %}
>
>
>
>
>
> *From: *Farai M 
> *Sent: *Wednesday, February 19, 2020 11:19 PM
> *To: *django-users@googlegroups.com
> *Subject: *Re: I am filling up the form but my filled out items are not
> rendering into database and also the session is not working
>
>
>
> The session must be activated in the settings file check that it should
> work smoothly.
>
> On the insert can u share the template file mostly .It is to do with post
> requests not reaching back end. You can try to print the post request
> before your save to model to see if all inputs are coming through.If it's
> not that try get create to see if it's an problem with duplicates.
>
>
>
>
>
>
>
>
>
>
>
>
>
> *views.py from *django.views.generic *import *FormView, TemplateView
> *from *django.shortcuts *import *render,redirect
> *from *.models *import 
> *modelstep1,modelstep2,modelstep3,modelstep4,modelstep5,modelstep6,modelstep7,modelstep8,modelstep9,modelstep10
> *from *.forms *import 
> *FormStep1,FormStep2,FormStep3,FormStep4,FormStep5,FormStep6,FormStep7,FormStep8,FormStep9,FormStep10
>
> *def *FormStep1View(request):
> forms = FormStep1()
> *return *render(request, *'form_1.html'*, context={*'form'*: forms})
>
>
> *def *addForm1(request):
> form = FormStep1(request.POST)
> *if *form.is_valid():
> u=modelstep1()
> u.name = form.cleaned_data[*'name'*]
> u.email = form.cleaned_data[*'email'*]
> u.link_sent = form.cleaned_data[*'link_sent'*]
> u.title = request.POST.get(*'name'*)
> u.content = request.POST.get(*'email'*)
> u.content = request.POST.get(*'link_sent'*)
> u.save()
> request.session[*'name'*] = u.name
> request.session[*'email'*] = u.email
> request.session[*'link_sent'*] =u.link_sent
> *return *redirect(*'/form/2/'*,context={*'form'*: form})
>
>
>
> *def *FormStep2View(request):
> forms = FormStep2()
> *return *render(request, *'form_2.html'*, context={*'form'*: forms})
> *def *addForm2(request):
> form = FormStep2(request.POST)
> *if *form.is_valid():
>   v=modelstep2()
>   v.country=form.cleaned_data[*'country'*]
>   v.city=form.cleaned_data[*'city'*]
>   v.year_of_birth=form.cleaned_data[*'year_of_birth'*]
>   v.current_grade=form.cleaned_data[*'current_grade'*]
>   v.university=form.cleaned_data[*' university'*]
>   v.school=form.cleaned_data[*'school'*]
>   v.native_language=form.cleaned_data[*'native_language'*]
>   v.phone_number = form.cleaned_data[*'phone_number'*]
>   v.email_business=form.cleaned_data[*'email_business'*]
>   v.social_media=form.cleaned_data[*'social_media'*]
>
>   request.session[*'country'*] = v.country
>   request.session[*'city'*] = v.city
>   request.session[*'year_of_birth'*] = v.year_of_birth
>   request.session[*'current_grade'*] = v.current_grade
>   request.session[*'university'*] = v.university
>   request.session[*'school'*] = v.school
>   request.session[*'native_language'*] = v.native_language
>   request.session[*'phone_number'*] = v.phone_number
>   request.session[*'email_business'*] = v.email_business
>   request.session[*'social_media'*]=  v.social_media
>   *return *redirect(request, *'/form/3/'*, 
> context={*'form'*:form})
>
>
> *def *FormStep3View(request):
> forms = FormStep3()
> *return *render(request, *'form_3.html'*, context={*'form'*: forms})
> *def *addForm3(request):
> form = FormStep3(request.POST)
> *if *form.is_valid():
>x=modelstep3()
>x.internship_idea = form.cleaned_data[*'internship_idea'*]
>x.startup_business = form.cleaned_data[*'startup_business'*]
>x.goals = form.cleaned_data[*'goals'*]
>x.established_year = form.cleaned_data[*'established_year'*]
>x.number_of_employees = form.cleaned_data[*'number_of_employees'*]
>x.months = form.cleaned_data[*'months'*]
>x.website = form.cleaned_data[*'website'*]
>x.cell_number_business = 
> form.cleaned_data[*'cell_number_business'*]

Re: Bootstrap not found

2020-02-17 Thread onlinejudge95
On Sun, Feb 16, 2020 at 8:36 PM Alessandro D' Oronzo 
wrote:

> Hi everyone,
> I have a problem with load bootstrap on my generic_template.
>
As best practices go around, try to include the static assets like CSS, js
from a CDN instead of downloading and manually serving them

>
> This is error output:
> [16/Feb/2020 14:57:37] "GET / HTTP/1.1" 200 2239
> [16/Feb/2020 14:57:37] "GET
> /static/vendor/bootstrap/css/bootstrap.min.css HTTP/1.1" 404 1740
> [16/Feb/2020 14:57:37] "GET
> /static/vendor/bootstrap/js/bootstrap.bundle.min.js HTTP/1.1" 404 1755
> [16/Feb/2020 14:57:37] "GET /static/css/the-big-picture.css HTTP/1.1" 404
> 1695
> [16/Feb/2020 14:57:37] "GET /static/vendor/jquery/jquery.min.js HTTP/1.1"
> 404 1707
> [16/Feb/2020 14:57:37] "GET
> /static/vendor/bootstrap/js/bootstrap.bundle.min.js HTTP/1.1" 404 1755
>
> Can someone help me?
> Thanks you!
>
> --
> 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/2F896088-95FB-4906-A2D5-0F8421907AE2%40gmail.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/CAD%3DM5eR9zN%2BfvnCkkCG6f7CQ%3D0DT3fBb6_7uqb9s1y235Mh%2BPA%40mail.gmail.com.


Re: How to create custom registration form in django rest api?

2020-02-17 Thread onlinejudge95
On Sun, Feb 16, 2020 at 3:19 PM maunish dave 
wrote:

> I am creating an health care app which need to include patients and
> doctors account, i have created Doctor model which have various info of
> doctor now i want a serializer  which maps this model to a proper html
> registration form.
>
You can use DRF serializers or use marshmallow

> My problem is that i can get a normal form rendered but it is only storing
> data to Doctors database but not creating a new user.
>
> --
> 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/CALpJ3uJj-hf-T5dx_5t6WXRqG_XRuex5r0MKE9E3gcHWCvFKDw%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/CAD%3DM5eTneAPrSYYv9%2BiY%3DUbGa3TKMNDvX7S8EZqXxH5qA%3D9gjA%40mail.gmail.com.


Re: Retaining text in search input boxes

2020-02-17 Thread onlinejudge95
On Sun, Feb 16, 2020 at 11:26 AM maninder singh Kumar <
maninder.s.ku...@gmail.com> wrote:

> Wouldn't the value field make it fixed ?
>
Sure but you can always grab what value to insert from your views. If it is
the first time form is being filled than simply use nothing as value, if
the user tries to submit the form and have an error then just fill the
values with corresponding data

>
>
> [image: --]
>
> Maninder Kumar
> [image: http://]about.me/maninder.s.kumar
> 
>
>
>
>
> On Sun, Feb 16, 2020 at 12:22 AM Dick Arnold  wrote:
>
>> I have a personnel database which has to be edited to keep it current.
>> I have created search parameters to find the person to edit.
>> The exact name of the person is not always known, therefore the name
>> field for searching can contain only a few of the characters.  This can
>> create a list of several people.
>> After the search parameters are entered a "Search" button is clicked and
>> the output, if any, is displayed in a table.
>> If the search parameters need to be improved, I want the original
>> (current) search argument to be retained in the argument field so I do not
>> need to re-type ALL the search parameters, just the ones I want to change.
>>
>> I have not been able to find a way to retain the value in the search
>> input box,
>>
>> Does anyone know how to accomplish this?
>>
>> Here's the input for one of the input boxes.
>>
>> 
>>
>> --
>> 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/92cfccd1-5916-4817-ae46-c612aa462610%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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABOHK3SPDFdvajS9GyqhxHSvXw5eEQpHU9ax7NOtFhsM4W_wyg%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/CAD%3DM5eSrte_tF0h6gVpmaG6iJZ7piXiekJjUL4d2zMQgL5SiZA%40mail.gmail.com.


Re: Image overwrite

2020-02-17 Thread onlinejudge95
On Sun, Feb 16, 2020 at 11:09 AM Soumen Khatua 
wrote:

> Hi Folks,
>
> I have a model where user can upload their image.
>

I am assuming you are not storing the image as a blob but rather as an
object in some object storage.


> But after uploading a new image the old image is still their but as for my
> convention if a user upload his new image the old image should not be
> their, If anyone know please tell me How I can do that??
>

You just need to UPDATE the path of your image to the new one and make sure
it is that path only that you serve back to the user. This goes well even
if you are storing the image as a blob in your DB(but I prefer not to, it
is a long debatable topic)


> Thank you
>
> Regards,
> Soumen
>
>
>
> --
> 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/CAPUw6Wa%3DhcFc0r-n6m37w-ZiQL%3DtJh8JeXX1dc2x2-HbZVyocA%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/CAD%3DM5eQ3QhUTYkEf-Tn2KOiRd8niWcJbD75YuBtCtOvyq6ksjg%40mail.gmail.com.


Re: Retaining text in search input boxes

2020-02-15 Thread onlinejudge95
On Sun, Feb 16, 2020 at 12:22 AM Dick Arnold  wrote:

> I have a personnel database which has to be edited to keep it current.
> I have created search parameters to find the person to edit.
> The exact name of the person is not always known, therefore the name field
> for searching can contain only a few of the characters.  This can create a
> list of several people.
> After the search parameters are entered a "Search" button is clicked and
> the output, if any, is displayed in a table.
> If the search parameters need to be improved, I want the original
> (current) search argument to be retained in the argument field so I do not
> need to re-type ALL the search parameters, just the ones I want to change.
>
> I have not been able to find a way to retain the value in the search input
> box,
>
> Does anyone know how to accomplish this?
>
> Here's the input for one of the input boxes.
>
> 
>

Set an attribute of value in your input tags, and use the form object in
your view to populate it. For reference
https://stackoverflow.com/questions/4880306/django-multiple-forms-and-keep-field-data-input-after-submission?rq=1


> --
> 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/92cfccd1-5916-4817-ae46-c612aa462610%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eS8moJTCzxTt_ufn9qOxuhyXQkYAw-N2TS249oVKcweqQ%40mail.gmail.com.


Re: Django server indention

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 9:02 PM Sathiya S 
wrote:

> How to format Indention in server?
>

Are you talking about how to indent your code in Django? If yes then a
learner's approach would be, well to do it yourself, I mean entire Python
depends on indentation right? You can also look at psf/black
 if you want to skip ahead.


> --
> 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/68652648-1dd6-4d33-9d6e-c069388d29a4%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eSfWiiAErd6DM656RmWJQNwwSEHBrBSV43rg8cLm7OKRA%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 8:14 PM sachinbg sachin 
wrote:

> Fistly for setup create use instance for setup user credentials then call
> that the reverse url in that post put delite
>

I have already created my test users in the *setUpClass()* method. As
mentioned my problem was not something related to URL dispatching but more
on how to prepare a POST request with the proper payload. I looked into the
documentation and RequestFactory is exactly what i was looking for.


> On Thu, Feb 13, 2020, 8:01 PM Adam Mičuda  wrote:
>
>> Hi,
>> or you can extract the business logic from view to some service and unit
>> test it instead. =)
>>
>> Regards.
>>
>> Adam
>>
>> st 12. 2. 2020 v 21:15 odesílatel onlinejudge95 
>> napsal:
>>
>>> On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
>>> wrote:
>>>
>>>> Hi Devs,
>>>>
>>>> I was implementing unit-tests in my Django project and stumbled upon
>>>> the following issue.
>>>>
>>>> I want to unit-test my POST route. I do not want to use the test client
>>>> already shipped with Django (using it in my e2e tests). I want to know how
>>>> do I prepare my request object to pass to my view. Here is what I have done
>>>> currently.
>>>>
>>>> test_views.py
>>>>
>>>>> class CreateBlogTest(BaseViewTest):
>>>>
>>>> @classmethod
>>>>> def setUpClass(cls):
>>>>> cls.request.method = "POST"
>>>>
>>>> def test_create_valid_blog(self):
>>>>> self.request.content_type = "application/json"
>>>>> self.request._body = json.dumps({"title": "new title", "body":
>>>>> "new body"})
>>>>>
>>>>> response = views.blog_collection(self.request)
>>>>> self.assertEqual(response.status_code, 201)
>>>>>
>>>>
>>>> In my view, I am accessing the data through *request.data* and passing
>>>> it to a serializer.
>>>>
>>>> In my current setting, I am getting a 400 error message when I have
>>>> checked that the user does not exist.
>>>>
>>>> Any suggestions regarding the same?
>>>>
>>>> Thanks,
>>>> onlinejudge95
>>>>
>>>
>>> In case if someone needs it in the future, go and look at
>>> *django.test.RequestFactory *
>>>
>>> https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory
>>>
>>> --
>>> 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/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com?utm_medium=email_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 django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com?utm_medium=email_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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAOs61rxaSRrE239aZrbBpZSo7QBoZx2BKxx4nBiERhio0RGSJg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAOs61rxaSRrE239aZrbBpZSo7QBoZx2BKxx4nBiERhio0RGSJg%40mail.gmail.com?utm_medium=email_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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eTyjickDTJVCMgHOGWVpXrTdS%2BRsyiJOtJSBpfWPrb44g%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 8:02 PM Adam Mičuda  wrote:

> Hi,
> or you can extract the business logic from view to some service and unit
> test it instead. =)
>

I am following the same, it's just that I am also performing serialization
as of now in my views, since I want to push it out first, and have
documented the refactor I would be performing. My question was on how to
prepare a post request with proper payload, while i was running this test
my response object was an empty dictionary.

>
> Regards.
>
> Adam
>
> st 12. 2. 2020 v 21:15 odesílatel onlinejudge95 
> napsal:
>
>> On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
>> wrote:
>>
>>> Hi Devs,
>>>
>>> I was implementing unit-tests in my Django project and stumbled upon the
>>> following issue.
>>>
>>> I want to unit-test my POST route. I do not want to use the test client
>>> already shipped with Django (using it in my e2e tests). I want to know how
>>> do I prepare my request object to pass to my view. Here is what I have done
>>> currently.
>>>
>>> test_views.py
>>>
>>>> class CreateBlogTest(BaseViewTest):
>>>
>>> @classmethod
>>>> def setUpClass(cls):
>>>> cls.request.method = "POST"
>>>
>>> def test_create_valid_blog(self):
>>>> self.request.content_type = "application/json"
>>>> self.request._body = json.dumps({"title": "new title", "body":
>>>> "new body"})
>>>>
>>>> response = views.blog_collection(self.request)
>>>> self.assertEqual(response.status_code, 201)
>>>>
>>>
>>> In my view, I am accessing the data through *request.data* and passing
>>> it to a serializer.
>>>
>>> In my current setting, I am getting a 400 error message when I have
>>> checked that the user does not exist.
>>>
>>> Any suggestions regarding the same?
>>>
>>> Thanks,
>>> onlinejudge95
>>>
>>
>> In case if someone needs it in the future, go and look at
>> *django.test.RequestFactory *
>>
>> https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory
>>
>> --
>> 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/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com?utm_medium=email_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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com?utm_medium=email_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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eTWpMRcZ%2BG_zRf%2B9hB2Xds3SKB%3Dm6PT5C60cCDvGUa5EA%40mail.gmail.com.


Re: Separating django business logiv from views

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 6:34 PM Mrunalini Ramnath 
wrote:

> Hey folks!
> I've been researching on effective ways to separate business logic from
> views.py. I currently also have separate files for helper functions but the
> codebase is still a little cluttered.
>

How about going on the traditional MVC way?

Your views act as controllers with only one concern i.e. to operate on the
HTTP plane, call services, raise exceptions maybe.

I generally create a *service.py* in each app to implement the business
logic and just call it inside my *views.py*. It helps to make my business
logic loosely coupled with the web-server. Also, it has an upside that it
makes testing easier.


> I found this method of implementation that involves creating a manager
> class for each model that can contain all the necessary functions, and thin
> views for executing said function. There are quite a few sources pertaining
> to this but I found this to be the strongest one in support so far:
> https://sunscrapers.com/blog/where-to-put-business-logic-django/#Idea_4_QuerySetsManagers
>
> Are there any more pros and cons that haven't been discussed in 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a893a097-c091-42ae-9638-ec4cf0ec8a9d%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eTWKRMcszkWA3EEEUbauQ7n3qKoB1VBrDc9BJ4uj9a%2BYQ%40mail.gmail.com.


Re: Manually running a script that imports a Django model

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 6:34 PM Sourish Kundu 
wrote:

> So I am trying to access one of my models created in views.py in another
> script. This second script is the one I would like manually run. It imports
> the model without any errors; however, when I try to run it using PyCharm,
> I get this error:
>

Firstly, what are your models doing in views.py? I am assuming it was a
typo.


>
> *django.core.exceptions.ImproperlyConfigured: Requested setting
> INSTALLED_APPS, but settings are not configured. You must either define the
> environment variable DJANGO_SETTINGS_MODULE or call settings.configure()
> before accessing settings.*
>
> Any help on resolving this issue would be very much appreciated.
>

For scripts like these that are not part of your web server or that do not
take part in the request-response cycle, I like to implement them as custom
Django commands. You can read more about them here
.


>
>
> Thanks,
> Sourish
>
> --
> 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/2c9b2d34-a9ab-4a2f-a1e4-e2694c265ea0%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eSBrbLvnFBzoGfOaJk3NnWG8t1N2aOQTmHR6TDsup3F%2BA%40mail.gmail.com.


Re: Django: how to make queries between 2 tables that are not related in the model?

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 2:59 PM Jérôme Le Carrou 
wrote:

> Hi,
>
> I have 2 models that are not related (maybe it should...)
>
> I need to make a query that select all records of my table Stock WITH
> related rows in Parametrage based on asp_sto_loc=asp_par_loc
>
> Something like SQL: select * from pha_asp_sto left join pha_asp_par on
> pha_asp_par.asp_par_loc=asp_sto_loc;
>

Have a look at django.db.models.SubQuery



How can I make such a query in Django?
> I have see extra() but seems to be deprecated...
> Another option would be to use raw() but not recommended...
>
> class Stock(models.Model):
>
> asp_sto_cle = models.AutoField(primary_key=True)
> asp_sto_loc = models.CharField("Site concerned", max_length=10, 
> null=True, blank=True)
> asp_sto_pla = models.IntegerField("Quantity of placebos available", 
> null=True, blank=True,)
> asp_sto_asp = models.IntegerField("Quantity of aspirin available", 
> null=True, blank=True)
> class Parametrage(models.Model):
>
> asp_par_cle = models.AutoField(primary_key=True)
> asp_par_loc = models.CharField("Site concerned by settings", 
> max_length=10, null=True, blank=True)
> asp_par_ale = models.IntegerField("Site alert value for the site", 
> null=True, blank=True,)
> asp_par_con = models.IntegerField("Site confort value for the site", 
> null=True, blank=True,)
>
> thanks for your help
>
> --
> 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/029c93e0-4093-4a4f-bc99-b3af000c3c31%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eQiPuR%3DsASF04wv6sdCUhiRu-oyfiLq60axZr%3D3qF-i0w%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-12 Thread onlinejudge95
On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
wrote:

> Hi Devs,
>
> I was implementing unit-tests in my Django project and stumbled upon the
> following issue.
>
> I want to unit-test my POST route. I do not want to use the test client
> already shipped with Django (using it in my e2e tests). I want to know how
> do I prepare my request object to pass to my view. Here is what I have done
> currently.
>
> test_views.py
>
>> class CreateBlogTest(BaseViewTest):
>
> @classmethod
>> def setUpClass(cls):
>> cls.request.method = "POST"
>
> def test_create_valid_blog(self):
>> self.request.content_type = "application/json"
>> self.request._body = json.dumps({"title": "new title", "body":
>> "new body"})
>>
>> response = views.blog_collection(self.request)
>> self.assertEqual(response.status_code, 201)
>>
>
> In my view, I am accessing the data through *request.data* and passing it
> to a serializer.
>
> In my current setting, I am getting a 400 error message when I have
> checked that the user does not exist.
>
> Any suggestions regarding the same?
>
> Thanks,
> onlinejudge95
>

In case if someone needs it in the future, go and look at
*django.test.RequestFactory *
https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory

-- 
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/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-12 Thread onlinejudge95
Hi Guys,

Any leads would be appreciated


On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
wrote:

> Hi Devs,
>
> I was implementing unit-tests in my Django project and stumbled upon the
> following issue.
>
> I want to unit-test my POST route. I do not want to use the test client
> already shipped with Django (using it in my e2e tests). I want to know how
> do I prepare my request object to pass to my view. Here is what I have done
> currently.
>
> test_views.py
>
>> class CreateBlogTest(BaseViewTest):
>
> @classmethod
>> def setUpClass(cls):
>> cls.request.method = "POST"
>
> def test_create_valid_blog(self):
>> self.request.content_type = "application/json"
>> self.request._body = json.dumps({"title": "new title", "body":
>> "new body"})
>>
>> response = views.blog_collection(self.request)
>> self.assertEqual(response.status_code, 201)
>>
>
> In my view, I am accessing the data through *request.data* and passing it
> to a serializer.
>
> In my current setting, I am getting a 400 error message when I have
> checked that the user does not exist.
>
> Any suggestions regarding the same?
>
> Thanks,
> onlinejudge95
>

-- 
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/CAD%3DM5eS3nFRxHm_aSqSt8YxFhaZGahF%3DP6Uj0Zco7wafM1%2BHOQ%40mail.gmail.com.


Unit Testing POST request

2020-02-12 Thread onlinejudge95
Hi Devs,

I was implementing unit-tests in my Django project and stumbled upon the
following issue.

I want to unit-test my POST route. I do not want to use the test client
already shipped with Django (using it in my e2e tests). I want to know how
do I prepare my request object to pass to my view. Here is what I have done
currently.

test_views.py

> class CreateBlogTest(BaseViewTest):

@classmethod
> def setUpClass(cls):
> cls.request.method = "POST"

def test_create_valid_blog(self):
> self.request.content_type = "application/json"
> self.request._body = json.dumps({"title": "new title", "body":
> "new body"})
>
> response = views.blog_collection(self.request)
> self.assertEqual(response.status_code, 201)
>

In my view, I am accessing the data through *request.data* and passing it
to a serializer.

In my current setting, I am getting a 400 error message when I have checked
that the user does not exist.

Any suggestions regarding the same?

Thanks,
onlinejudge95

-- 
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/CAD%3DM5eSYo5vSZc8SNGnCET-A10%2B%2Bz6q9j0vqy85TU6r0tE957A%40mail.gmail.com.


Re: Problem with Admin Page

2020-02-10 Thread onlinejudge95
Also, traceback would be awesome

On Mon, Feb 10, 2020 at 12:09 AM Alessandro D' Oronzo 
wrote:

> Hi everyone,
> I have a problem with local web server and admin page.
> When I try to connect to admin page the web server of Django close without
> errors.
> Do you have any ideas?
>
> Thanks so much!
>
> --
> 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/DB0F065D-5D63-438D-B5AA-DBFB05B28A54%40gmail.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/CAD%3DM5eQZY5oOp-9p7oxSOG_Y8fVEiZDEaDHBqpzQfo8%2BfpfwxQ%40mail.gmail.com.


Re: to add counter to an object of a table

2020-02-10 Thread onlinejudge95
Can you be more specific and provide more context about the same

On Mon, Feb 10, 2020 at 12:15 AM BRAJESH KUMAR 
wrote:

> Hi ,
>
> I have a product details db class with few details for each object of that
> class, need help to add a counter.
>
>
>
> Thanks,
>
> Brajesh
>
>
>
>
>
> Sent from Mail  for
> Windows 10
>
>
>
> --
> 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/5e405315.1c69fb81.6e215.a4ec%40mx.google.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/CAD%3DM5eR7FxGFfd4T7psq6rtTNoD8FyYjaeKoozUDeq52heWk%3DA%40mail.gmail.com.


Re: Trie Data Structure

2020-02-08 Thread onlinejudge95
I am ready to answer your question, but not here it's a Django User's
Group. The question you are asking is about implementation of an algorithm
which is language agnostic. Technically, it shouldn't be asked in the
Python Mailing list too.

Keep a watch on your inbox though. :)

Thanks,
onlinejudge95

On Sat, Feb 8, 2020, 3:06 PM Soumen Khatua 
wrote:

> from collections import defaultdict
>
>
> class TrieNode():
>
> def __init__(self):
> self.children = defaultdict()
> self.terminating = False
>
>
> class Trie():
>
> def __init__(self):
> self.root = self.get_node()
>
> def get_node(self):
> return TrieNode()
>
> def get_index(self, ch):
> return ord(ch) - ord('a')
>
> def insert(self, word):
>
> root = self.root
> len1 = len(word)
>
> for i in range(len1):
> index = self.get_index(word[i])
>
> if index not in root.children:
> root.children[index] = self.get_node()
> root = root.children.get(index)
>
> root.terminating = True
>
> def search(self, word):
> root = self.root
> len1 = len(word)
>
> for i in range(len1):
> index = self.get_index(word[i])
> if not root:
> return False
> root = root.children.get(index)
>
> return True if root and root.terminating else False
>
> def delete(self, word):
>
> root = self.root
> len1 = len(word)
>
> for i in range(len1):
> index = self.get_index(word[i])
>
> if not root:
> print ("Word not found")
> return -1
> root = root.children.get(index)
>
> if not root:
> print ("Word not found")
> return -1
> else:
> root.terminating = False
> return 0
>
> def update(self, old_word, new_word):
> val = self.delete(old_word)
> if val == 0:
> self.insert(new_word)
>
>
>
> if __name__ == "__main__":
>
> strings = ["pqrs", "pprt", "psst", "qqrs", "pqrs"]
>
> t = Trie()
> for word in strings:
> t.insert(word)
>
>
> Could anyone tell me,How Inset function is working here? actually I'm not
> able to track it. Specially if index is alerady available in root.children
> then how it is creating an another TrieNode object.
>
> Thank you 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/CAPUw6WbzxcxyzwKynS9vnZe5cwem2bT8bjLZS%2BO9C%2BfyV6V6MA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAPUw6WbzxcxyzwKynS9vnZe5cwem2bT8bjLZS%2BO9C%2BfyV6V6MA%40mail.gmail.com?utm_medium=email_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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eTHoFBbwPiMphieWSB8pemHM0Tzs_r1CjfjdPVB0NWCaw%40mail.gmail.com.


Re: How to best secure environment variables (secret key, passwords etc.) stored in .yml files?

2020-02-08 Thread onlinejudge95
+1 for the same

On Thu, Jan 30, 2020, 8:17 PM Chris Wedgwood  wrote:

> Hi Tom
>
> You are definitely not overthinking this. it's important.
>
> This is an area that has baked my noodle for a while now and I always am
> left wondering "Do I have this right?" "Am I vulnerable to attack?" .
> and I still haven't figured it out completely. It's like static files  I
> never really feeel like I get it entirely :)
>
> Firstly you should never need to store a password/token/secret in Source
> Control ever. If you are stop and think there must be a better way.
>
> I use environment variables .env to store my secrets but the trick is
> ALWAYS put that in your .gitignore  file. If you start a new git repository
> there is an option to create a .gitignore file
> for Python that is a great starting point.
>
> To complement my *.env* file it has a .env.example file that I DO put in
> source control with a dummy password.
>
> .env file:
>
> MAILGUN_API_KEY =asjdhasds78dy9s8dy012287e210eu209e72
>
> .env.example:
>
> MAILGUN_API_KEY=ThisIsNotARealToken
>
> So when I do local development  I can populate my .env fie with local dev
> secrets.
>
> For production deployments, I use *Ansible *for which I provide
> production tokens and secrets in a separate file also not in source control.
>
> The Ansible deployment requires an ssh password that I store in a Password
> Manager that has two-factor authentication.
>
> The docker-compose file can read environment variables from the .env file.
>
> Have a look at Django-Cookiecutter and see how they do it. That helped me
> a lot when I started out
>
> cheers
> Chris
>
>
>
>
>
>
>
>
>
>
>
> On Thursday, 30 January 2020 12:41:01 UTC, Tom Moore wrote:
>>
>> Hi there, I'm following the guidelines by making sure the environment
>> variables are stored outside of the settings.py files.
>>
>> The project is "dockerised" and so the environment variables have been
>> stored in files *docker-compose.yml* and *docker-compose-prod.yml*.
>>
>> This includes things like the project's secret key, API keys, and
>> database passwords.
>>
>> *My question is: *
>> • Just because environment variables are stored in .yml files, won't they
>> be equally insecure the moment I commit the project folder to a git repo
>> (and especially if I push that repo to GitHub)?
>> e.g. the Secret Key will forevermore be stored in the git repo (in
>> earlier versions, even if I later move it to another file in subsequent
>> commits).
>>
>> Is there an even more secure way of storing environment variables? Or am
>> I overthinking it (as I'm the only developer and the GitHub repo is set to
>> Private)?
>>
>> Many thanks in advance for your help.
>>
> --
> 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/55f28dec-7c9a-4cae-b658-f89772aa1bd7%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eTLPJKDendsP9DvYzi_bDXhOYFZgNG5ZEBsLg7bknGO2g%40mail.gmail.com.


Re: Key Error :access_token While requesting access token using windows Outlook api token url

2020-02-07 Thread onlinejudge95
Firstly, do not ever share any of your personal information over a mailing
list. You just exposed your token and auth_code to the public domain.

Secondly, you need to provide more context, you said an error came up but
did not provide any insight into the code you are executing.

On Fri, Feb 7, 2020 at 7:15 PM Aakash Verma <4k45hr0ck5...@gmail.com> wrote:

> Below is the Traceback
>
> [07/Feb/2020 13:15:44] "GET
> /tutorial/gettoken?code=M75b5bb08-f43a-3749-bcd6-bdc1595306d9 HTTP/1.1"
> 301 0
> Internal Server Error: /tutorial/gettoken/
> Traceback (most recent call last):
>   File
> "C:\Users\lenovo\Desktop\myapi\v\lib\site-packages\django\core\handlers\exception.py"
> , line 34, in inner
> response = get_response(request)
>   File
> "C:\Users\lenovo\Desktop\myapi\v\lib\site-packages\django\core\handlers\base.py"
> , line 115, in _get_response
> response = self.process_exception_by_middleware(e, request)
>   File
> "C:\Users\lenovo\Desktop\myapi\v\lib\site-packages\django\core\handlers\base.py"
> , line 113, in _get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs
> )
>   File "C:\Users\lenovo\Desktop\myapi\python_tutorial\tutorial\views.py",
> line 17, in gettoken
> access_token = token['access_token']Below is th Trace back
> KeyError: 'access_token'
>
>
> I  was Following this tutorial
> https://docs.microsoft.com/en-us/outlook/rest/python-tutorial  and had an
> issue of acces_token , Can anyone  help me how to solve that ?
> I have double checked for every line of my code and done with checking
> redirect_uri also , It would be grateful of you if you can help .Thanks .
> Checked StackOverFlow also ,it seems like there is no relevant answer for
> this is the response error i am getting while requesting for acces_token
>
> auth_code
>
> 'M75b5bb08-f43a-3749-bcd6-bdc1595306d9'
>
> redirect_uri
>
> 'http://localhost:8000/tutorial/gettoken/'
>
> request
>
>  '/tutorial/gettoken/?code=M75b5bb08-f43a-3749-bcd6-bdc1595306d9'>
>
> token
>
> {'correlation_id': 'b7bbadc7-9031-419c-8e5e-2be3fddfbf22',
>  'error': 'invalid_client',
>  'error_codes': [50011],
>  'error_description': 'AADSTS50011: The reply URL specified in the request '
>   'does not match the reply URLs configured for the '
>   "application: '38ae3415-e1fb-4829-8381-396fbeee2230'. "
>   'More details: Reply address did not match because '
>   'requested address did not have a trailing slash.\r\n'
>   'Trace ID: 48237da8-3830-488c-bd49-e081435a6700\r\n'
>   'Correlation ID: 
> b7bbadc7-9031-419c-8e5e-2be3fddfbf22\r\n'
>   'Timestamp: 2020-02-07 07:45:44Z',
>  'error_uri': 'https://login.microsoftonline.com/error?code=50011',
>  'timestamp': '2020-02-07 07:45:44Z',
>  'trace_id': '48237da8-3830-488c-bd49-e081435a6700'}
>
>
> But the thing is I have thoroughly checked my code and ithere seems no
> error . I have been getting this error since last night ..Please HELP if
> possible
>
> --
> 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/d7e0ca1b-9c37-4c52-999a-548454caaf20%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eQMEYNapt%2BzXgT%3DSEY2qqq9af_5bnZvAfBq0YdFAeNmXg%40mail.gmail.com.


Re: Lots of errors after deploying and going live

2020-02-06 Thread onlinejudge95
It might be out of point but the moment you start noticing these errors
repeatedly is the time you start considering using docker.

On Tue, Feb 4, 2020 at 4:07 PM Dave Ko  wrote:

> Hi guys, so this is a very general post, I have been working on a django
> blog following Corey Schafer's Django tutorial.
>
> Everything went smoothly on local machine, but once I deployed it, I am
> having all kinds of troubles.
> From password_reset (still not solved) to uploading image ran into error
> of register_open() missing factory, all of the troubles didn't occur on
> local machine.
>
> I had some experience with expressjs development, there were no difference
> before and after deploy.
> As for Django, there are so many errors I couldn't find the answer
> including here and stackoverflow, have you guys face similar situation?
>
> here is my git repository, please have a look and point out the problems i
> have https://github.com/koloyyee/roasitas
>
> --
> 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/b0066211-a642-4e64-9728-55a824930b78%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eRv7csP2n2eewLkg768z%2BUD1zm69D3UjVAekG%2B%2BBHWkUQ%40mail.gmail.com.


Problem with serialising POST, PUT request in DRF

2020-02-06 Thread onlinejudge95
Hi Devs,

I am trying to implement a CRUD app(modeling blogs) using Django & DRF. I
am using *rest_framework.serializers.ModelSerializer* for serializing my
model. While sending a POST, PUT request the serializer is not saving my
data, what am I missing?

*terminal*

> Request data:- {'title': 'title 2', 'body': 'body 2'}
> Serialized data:- {'pk': 2, 'title': '', 'body': ''}
> [06/Feb/2020 17:19:36] "POST /api/blog/ HTTP/1.1" 201 29
> [06/Feb/2020 17:19:44] "GET /api/blog/ HTTP/1.1" 200 168


*views.py*

> from blog.models import Blog
> from blog.serializers import BlogSerializer
> from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
> from rest_framework import status
> from rest_framework.decorators import api_view
> from rest_framework.response import Response
>
>
> @api_view(["GET", "POST"])
> def blog_collection(request):
> """
> API for operations on blogs, handles following operations
> 1. Fetch(GET) the list of blogs.
> 2. Create(POST) a new blog entry.
> """
> if request.method == "POST":
> print(f"Request data:- {request.data}")
> if request.data == dict():
> return Response(status=status.HTTP_400_BAD_REQUEST)
>
> serializer = BlogSerializer(data=request.data)
>
> if serializer.is_valid():
> serializer.save()
> print(f"Serialized data:- {serializer.data}")
> return Response(serializer.data, status=status.HTTP_201_CREATED)
>
> return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
>
*serializers.py*

> from blog.models import Blog
> from rest_framework import serializers
>
>
> class BlogSerializer(serializers.ModelSerializer):
> class Meta:
> model = Blog
> fields = ("pk", "title", "body")
>
>
*model.py*

> from django.db import models
>
>
> class Blog(models.Model):
> _title = models.CharField("Title", max_length=250)
> _body = models.TextField("Body")
>
> @property
> def title(self):
> return self._title
>
> @title.setter
> def title(self, value):
> self._title = value
>
> @property
> def body(self):
> return self._body
>
> @body.setter
> def body(self, value):
> self._body = value
>
> @staticmethod
> def get_blogs():
> return Blog.objects.all().order_by("id")
>
> @staticmethod
> def get_by_pk(pk):
> return Blog.objects.get(pk=pk)
>
> @staticmethod
> def get_by_attributes(attributes):
> return Blog.objects.get(**attributes)
>
> @staticmethod
> def create_blog(data):
> obj = Blog.objects.create(**data)
> obj.save()
> return obj
>
> @staticmethod
> def update_blog(pk, data):
> Blog.objects.filter(pk=pk).update(**data)
>
> @staticmethod
> def delete_blog(pk):
> Blog.objects.get(pk=pk).delete()
>
> def __str__(self):
> return f""
>
>

-- 
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/CAD%3DM5eQs-%2B-htfmsVk_bxqh9WSiS_PxLQcohsHz6r%2BRW%3DhDz7g%40mail.gmail.com.


Re: Best Django Deployment

2020-01-23 Thread onlinejudge95
+1 on the question.
Mainly whether the Apache + modWSGI or Nginx is the better way to go.

On Fri, Jan 24, 2020, 7:41 AM Aldian Fazrihady  wrote:

> Google AppEngine fFex will handle everything for you, but for my
> requirement, the price is too expensive, so I don't use it and I also don't
> use any Google cloud product to host my Django app.
> If your app code is not efficient, it means it will use more resources,
> then the monthly bill of AppEngine Flex will also be higher.
>
> Google AppEngine flex is using nginx.
>
> On Fri, Jan 24, 2020 at 2:46 AM Motaz Hejaze  wrote:
>
>> Any help friends ?
>>
>> --
>> 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/841a0431-f1c0-473b-85df-4e6377f2bbdd%40googlegroups.com
>> .
>>
>
>
> --
> Regards,
>
> Aldian Fazrihady
> http://aldianfazrihady.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/CAN7EoAbT10tmK87u_kLVLqYHV-JUnBgEPDziq%3DjfTwXkfjqzLA%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/CAD%3DM5eTMot%3D59RCXhDkwwdQZDU7bCioJuFd2x-SFJr2UboYFZA%40mail.gmail.com.


Understanding of GIL

2019-12-19 Thread onlinejudge95
Hi Devs,

I am currently writing some custom Django commands for data updation, my
workflow is like

Fetch data from *PostgreSQL*.
Call *Elasticsearch* for searching based on the data fetched from
*PostgreSQL*.
Query *PostgreSQL* and do an upsert behavior.
I am using pandas data frame to hold my data during processing.

The host we are using to run this jobs has a *CPython* interpreter as given
by

`platform.python_implementation()`

I want to confirm whether *multithreading* would be a better choice here,
given the fact that GIL is the biggest blocker(I agree it has to be there)
for the same in CPython interpreters.

In case further information is required do let me know.

Thanks
onlinejudge95

-- 
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/CAD%3DM5eRWh9-EB180f2OzvnPLHh969vgaCzFyniFRSFa1-CwUHA%40mail.gmail.com.


Using generators in Django

2019-12-18 Thread onlinejudge95
Hi Devs,

A quick question. I am using Django to schedule some commands to populate
my PostgreSQL(Apart from using it as a web framework). I am currently
fetching records from a particular table and for each of those records
doing some calculation and storing the processed data in some other
database. The skeleton code looks like this

```
...
def fetch_needs(project_id):
for item in MyNeedsModel.filter(project_id=project_id).all():
yield item
...

class Command(django.core.management.base.BaseCommand):
def add_argument(self, parser):
...
def handler(self, *args, **kwargs):
project = (args[0], args[1])
project_id = MyProject.filter(...).id
for need in fetch_needs(project_id):

```

I need to know whether the use of generators is correct here, in the sense
that would it have any performance issues. The point that I am having
trouble understanding is a comment on my code review.

Also don’t use generator you are bypassing django inbuilt caching
> mechanism. Using integrator it will create another list and get them one by
> one


Any help would be appreciated.

Thanks,
onlinejudge95

-- 
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/CAD%3DM5eSsCtNGh_MFRX2DM6dY1nTmS8vehWWaQHqeH1Jfo1VujQ%40mail.gmail.com.


Unit-Testing Django Views

2019-03-28 Thread OnlineJudge95
Hi people,

I am following the book Test-Driven Development with Python 

 by 
*Harry J.W. Perceval.* The book is using Django version 1.7 which is 
outdated as of now so I started with version 2.1.

I am trying to unit test my index view. One unit-test that I have written 
is testing whether the index view returns correct HTML or not by comparing 
the input received through
django.template.loader.render_to_string
the unit-test fail with the following traceback
python manage.py test
Creating test database for alias 'default'...
.System check identified no issues (0 silenced).
F.
==
FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
--
Traceback (most recent call last):
  File "tests.py", line 24, in test_index_view_returns_correct_html
self.assertEqual(expected_html, actual_html)
AssertionError: '\n' != 
'\n'

--
Ran 3 tests in 0.006s

FAILED (failures=1)
Destroying test database for alias 'default'...

Process finished with exit code 1


It was clear that the csrf token is causing the test to fail. Is there any 
way to test it, or should it be tested? I ask this as when I changed my 
Django version to 1.7, the tests were passing, even after giving the csrf 
token field in the form. I tried going through the changelogs but 1.7 is 
far behind (beginner here). Please find the code snippets, directory 
structure provided below.


*lists/views.py*










*from django.http import HttpResponsefrom django.shortcuts import render# 
Create your views here.def index(request):if request.method == 'POST':  
  return HttpResponse(request.POST['item_text'])return render(request, 
'index.html')*


*lists/test.py*


























*from django.http import HttpRequestfrom django.template.loader import 
render_to_stringfrom django.test import TestCasefrom django.urls import 
resolvefrom lists.views import index# Create your tests here.class 
IndexViewTest(TestCase):def 
test_root_url_resolves_to_home_page_view(self):   [...]def 
test_index_view_returns_correct_html(self):request = HttpRequest()  
  response = index(request)actual_html = 
response.content.decode()expected_html = 
render_to_string('index.html', request=request)
self.assertEqual(expected_html, actual_html)def 
test_index_view_can_save_a_post_request(self):   [...]requirements.txt*





*Django==2.1.7pytz==2018.9selenium==3.141.0urllib3==1.24.*
*settings.py*















*[...]# Application definitionINSTALLED_APPS = [ 'django.contrib.admin', 
'django.contrib.auth', 'django.contrib.contenttypes', 
'django.contrib.sessions', 'django.contrib.messages', 
'django.contrib.staticfiles', 'lists',][...]*
*Directory Structure*

[image: Screen Shot 2019-03-28 at 9.36.56 PM.png]

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ed387060-93e5-4d0c-a4a6-a5204e6c097f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.