Tuesday, June 30, 2020

Django bugfix releases issued: 3.0.8 and 2.2.14

Details are available on the Django project weblog:

https://www.djangoproject.com/weblog/2020/jul/01/django-bugfix-releases-308-2214/

How to display a line graph in Django?

Hi all, 

I have wrote a python program to display the line graph as follows: 

import matplotlib.pyplot as plt

x
= [1,2,3]
y
= [2,4,1]
 

plt
.plot(x, y)
 

plt
.xlabel('x - axis')
plt
.ylabel('y - axis')
 

plt
.title('My first graph!')
 
plt
.show()


Now I need to display the same via Django. So I think I need to write the above code in the view and then redirect the same to the html template file. Am I right?

In that case, how to send the request objects related to the line chart to the template?

Normally, we send in the following format:

def view1(request)


 
return render(request, 'display_report.html', { 'var1': "abc", ...
 
... })

So if we are trying to display the line graph generated by the above code, how to do so ? 

Please share your inputs. 

Thanks. 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/827e0d0c-6bbb-4511-af73-9fa379df699do%40googlegroups.com.

Need suggestions-Reg

Hi ,
    I need to integrate the video conferencing in my Django application.which is the best open source video conferencing tool available .please suggest me.

Thanks and Regards
Pavan T

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFJPboZZJmF5Z-nnT6MLui%2BP8AzvMB3i3itzXFNZEUPyiSe%3D_g%40mail.gmail.com.

Re: Can anybody answe how i can access infromation from the parent modell i my HTML template in Django?

Thank you friend, it worked

Den tisdag 30 juni 2020 kl. 13:22:11 UTC+2 skrev Andréas Kühne:
All you need to do is update the render call a dictionary with the customuser variable in it:

return render(request, 'members/member_contact_form.html', {'ContactFormset':ContactFormset, 'Address Formset':AddressFormset, 'customuser': customuser })

Regards,

Andréas


Den tis 30 juni 2020 kl 11:06 skrev The Sha <mah...@gmail.com>:
Ok i understand, how du i put the CustomUser in the render method so i cant get {{ CustomUser.first_name }} in this case?

Den tisdag 30 juni 2020 kl. 11:00:53 UTC+2 skrev Andréas Kühne:
Hi,

You need to pass the variables that you want to use in the template to the template itself. You do this here:
return render(request, 'members/member_contact_form.html', {'ContactFormset':ContactFormset, 'AddressFormset':AddressFormset })
The dictionary you add to the render method there contains all the objects that you can get in the template itself. So if you want to add something called object you need to add that to the dictionary.

Med vänliga hälsningar,

Andréas

Den tis 30 juni 2020 kl 10:38 skrev The Sha <mah...@gmail.com>:


I have a two formsets rendered in a view called ContactIndex, the parent model for this view is the CustomUser model. I want to present the first_name of the user object in my html template. I've tried these tags without success any advise?

This is the tags in my HTML template:

{{ customuser.first_name }} - does not work

{{ object.first_name }} - does not work


This is my view:

def ContactIndex(request, CustomUser_id):          customuser = CustomUser.objects.get(pk=CustomUser_id)          if request.method == "POST":              ContactFormset = ContactInlineFormSet(request.POST, request.FILES, instance=customuser)              AddressFormset = AddressInlineFormSet(request.POST, request.FILES, instance=customuser)              if ContactFormset.is_valid() or AddressFormset.is_valid():                  AddressFormset.save()                  ContactFormset.save()                  # Do something. Should generally end with a redirect. For example:                  return redirect ('ContactIndex', CustomUser_id=customuser.id)          else:              ContactFormset = ContactInlineFormSet(instance=customuser)              AddressFormset = AddressInlineFormSet(instance=customuser)          return render(request, 'members/member_contact_form.html', {'ContactFormset':ContactFormset, 'Address    Formset':AddressFormset })

--
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/865ff205-9a1d-4f62-bbe4-d2d12da22374o%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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2ab18788-3a31-4c7f-bba7-890580540153o%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/036bac0e-f999-401e-afd6-7a14f940bf5fo%40googlegroups.com.

Re: Can anybody answe how i can access infromation from the parent modell i my HTML template in Django?

It worked thank you my friend!

Den tisdag 30 juni 2020 kl. 11:00:53 UTC+2 skrev Andréas Kühne:
Hi,

You need to pass the variables that you want to use in the template to the template itself. You do this here:
return render(request, 'members/member_contact_form.html', {'ContactFormset':ContactFormset, 'AddressFormset':AddressFormset })
The dictionary you add to the render method there contains all the objects that you can get in the template itself. So if you want to add something called object you need to add that to the dictionary.

Med vänliga hälsningar,

Andréas

Den tis 30 juni 2020 kl 10:38 skrev The Sha <mah...@gmail.com>:


I have a two formsets rendered in a view called ContactIndex, the parent model for this view is the CustomUser model. I want to present the first_name of the user object in my html template. I've tried these tags without success any advise?

This is the tags in my HTML template:

{{ customuser.first_name }} - does not work

{{ object.first_name }} - does not work


This is my view:

def ContactIndex(request, CustomUser_id):          customuser = CustomUser.objects.get(pk=CustomUser_id)          if request.method == "POST":              ContactFormset = ContactInlineFormSet(request.POST, request.FILES, instance=customuser)              AddressFormset = AddressInlineFormSet(request.POST, request.FILES, instance=customuser)              if ContactFormset.is_valid() or AddressFormset.is_valid():                  AddressFormset.save()                  ContactFormset.save()                  # Do something. Should generally end with a redirect. For example:                  return redirect ('ContactIndex', CustomUser_id=customuser.id)          else:              ContactFormset = ContactInlineFormSet(instance=customuser)              AddressFormset = AddressInlineFormSet(instance=customuser)          return render(request, 'members/member_contact_form.html', {'ContactFormset':ContactFormset, 'Address    Formset':AddressFormset })

--
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/865ff205-9a1d-4f62-bbe4-d2d12da22374o%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0e80aec7-2a58-41d8-8125-425db2231313o%40googlegroups.com.