Re: Why I can't pass anything to my html? Django 2.1

2018-11-12 Thread Cuneyt Mertayak
vvv Typo: read "context" instead of "content" vvv

On Monday, November 12, 2018 at 5:26:48 AM UTC-8, Cuneyt Mertayak wrote:
>
> The content for the `render` method is supposed to be a dictionary: 
> https://docs.djangoproject.com/en/2.1/topics/http/shortcuts/#optional-arguments
>
> So change it to this render(requset, "FrounterWeb/body.html",{'tank': 
> tank})
>
> Also in the template file you want to display the properties of the ORM 
> (tank_system) object I guess, change them to {{tank.EC}}, 
> {{tank. temp}}, respectively.
>
> Hope it helps!
>
> On Monday, November 12, 2018 at 4:13:21 AM UTC-8, Rookies DJ wrote:
>>
>> I been trying 2 weeks on trying to pass variables form Django views into 
>> html, but every time I run my code, it works but it doesn't display the 
>> variable I see 
>>
>> from django.shortcuts import render
>> from zigview.models import tank_system
>>
>> def index(request):
>> return render(request,'FrounterWeb/includes.html')
>>
>> def login(requset):
>> return render(requset, 'FrounterWeb/login.html')
>>
>>
>> def timedex(requset):
>> tank = tank_system.object.get(id(5))
>> print(tank)
>> return render(requset, "FrounterWeb/body.html",tank)
>>
>>
>> Here my models
>>
>> from django.db import models
>>
>>
>> class user(models.Model):
>> username = models.CharField(max_length=50)
>> password = models.CharField(max_length=50)
>>
>>
>> class tank_system(models.Model):
>> Ph = models.DecimalField(max_digits=2, decimal_places=1)
>> EC = models.DecimalField(max_digits=2, decimal_places=1)
>> temp = models.DecimalField(max_digits=2, decimal_places=0)
>> level = models.IntegerField(primary_key=True, default=0)
>> data = models.DateTimeField(auto_now=True)
>>
>>
>> Here my HTML that i try pass variable in 
>>
>> 
>> 
>>   Time
>>   Tank level
>>   EC
>>   pH
>>   room temptures
>>   Water temptrure
>> 
>> 
>>   22.30
>>   900 lits
>>   {{tank}}
>>   7.3
>>   {{tank}}
>>   24
>> 
>>
>> 
>>
>>
>> My HTML body structures
>>
>> Web
>>
>> ├── templates
>> │   ├── index.hmtl
>> │   │   └── includes
>> │   ├── body.hml
>> │   ├── header.html
>>
>>   This my urls files;
>>
>> from django.contrib import admin
>> from django.urls import include, path
>> from django.views.generic.base import TemplateView
>>
>> urlpatterns = [
>> path(r'^admin/$', admin.site.urls),
>> path('account', include('django.contrib.auth.urls')),
>> path('', include('zigview.urls')),
>> path(r'', TemplateView.as_view(template_name='index.html'), name = 
>> 'myapp'),
>> ]
>>
>>

-- 
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/0ccdcf5d-1d90-41e4-be33-f3684dace2b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why I can't pass anything to my html? Django 2.1

2018-11-12 Thread Cuneyt Mertayak
The content for the `render` method is supposed to be a 
dictionary: 
https://docs.djangoproject.com/en/2.1/topics/http/shortcuts/#optional-arguments

So change it to this render(requset, "FrounterWeb/body.html",{'tank': tank})

Also in the template file you want to display the properties of the ORM 
(tank_system) object I guess, change them to {{tank.EC}}, 
{{tank. temp}}, respectively.

Hope it helps!

On Monday, November 12, 2018 at 4:13:21 AM UTC-8, Rookies DJ wrote:
>
> I been trying 2 weeks on trying to pass variables form Django views into 
> html, but every time I run my code, it works but it doesn't display the 
> variable I see 
>
> from django.shortcuts import render
> from zigview.models import tank_system
>
> def index(request):
> return render(request,'FrounterWeb/includes.html')
>
> def login(requset):
> return render(requset, 'FrounterWeb/login.html')
>
>
> def timedex(requset):
> tank = tank_system.object.get(id(5))
> print(tank)
> return render(requset, "FrounterWeb/body.html",tank)
>
>
> Here my models
>
> from django.db import models
>
>
> class user(models.Model):
> username = models.CharField(max_length=50)
> password = models.CharField(max_length=50)
>
>
> class tank_system(models.Model):
> Ph = models.DecimalField(max_digits=2, decimal_places=1)
> EC = models.DecimalField(max_digits=2, decimal_places=1)
> temp = models.DecimalField(max_digits=2, decimal_places=0)
> level = models.IntegerField(primary_key=True, default=0)
> data = models.DateTimeField(auto_now=True)
>
>
> Here my HTML that i try pass variable in 
>
> 
> 
>   Time
>   Tank level
>   EC
>   pH
>   room temptures
>   Water temptrure
> 
> 
>   22.30
>   900 lits
>   {{tank}}
>   7.3
>   {{tank}}
>   24
> 
>
> 
>
>
> My HTML body structures
>
> Web
>
> ├── templates
> │   ├── index.hmtl
> │   │   └── includes
> │   ├── body.hml
> │   ├── header.html
>
>   This my urls files;
>
> from django.contrib import admin
> from django.urls import include, path
> from django.views.generic.base import TemplateView
>
> urlpatterns = [
> path(r'^admin/$', admin.site.urls),
> path('account', include('django.contrib.auth.urls')),
> path('', include('zigview.urls')),
> path(r'', TemplateView.as_view(template_name='index.html'), name = 
> 'myapp'),
> ]
>
>

-- 
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/7973bb6a-6b32-468f-9c21-a2c5c47e8880%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Passing values from Python to Javascript

2018-05-24 Thread Cuneyt Mertayak
It is going to be like following.

In HTML (doesn't have to be div of course any HTML tag can get data 
attribute:
...

Then in JS:
var dataElement = document.getElementById('backend-to-js-name');
var name = dataElement.dataset.name;
console.log(name);

Check it out "data" attributes 
here: 
https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

On Thursday, May 24, 2018 at 6:44:39 AM UTC-7, Akshay Gaur wrote:
>
> Hi Cuneyt,
> How do you add the data fields and their values to tags generated by 
> python? For example, how would you add a data field to something generated 
> by {{ form.name }}?

-- 
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/642d449e-4241-4c63-9330-f392396196a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Passing values from Python to Javascript

2018-05-23 Thread Cuneyt Mertayak
As you can guess this is general problem for all backend languages for 
passing data to JS. 

AFAIK the standard practice is attaching the value to a DOM element as 
"data" property and using fetching the value from that element in your JS. 
If it is a primitive value it is easy to do so, if it is relatively complex 
structure, e.g. dictionary of classes etc. you can create a string 
representation of it (maybe in JSON format) and pass it to the template. 
Check out this link's method #4, it is on .NET but the idea is the 
same: 
https://blog.mariusschulz.com/2014/02/05/passing-net-server-side-data-to-javascript.

Hope it helps!

On Wednesday, May 23, 2018 at 4:52:05 AM UTC-7, steve Valet wrote:
>
> I am trying to pass values from Django/Python to Javascript, and have it 
> working to a degree, but need some assistance (obligatory: I'm new to 
> Django so could be hosing this)
>
> I have three files in play here, *views.py, app.js, home.html*. I can get 
> the values passed to home.html as part of the render, but I can't get the 
> code to work outside of the home.html file. Below is a *very simplified* 
> example of what I'm doing. 
>
> *VIEWS.PY*
>
> return render(request, "home.html", {'data':data'})
>
>
> *HOME.HTML*
>
> 
>
>  
>
>   
>
>   
>
>myFunction({{ data | safe }});
>
>   
>
>  
>
> 
>
>
> *APP.JS*
>
> function *myFunction*(vars){
>
> return vars
>
> };
>
>
>
>
> I would like to have the JS in the HTML file in the APP.JS file so I can 
> centralize all Javascript, but cannot get it to work outside the HTML. I also 
> tried sending the "data" to JSON using "json.dumps" but got an error that the 
> data was not serializable, so went with this code posted above.
>
>
> Can I do what I'm trying to do?
>
>
> Thanks
>
> Steve
>
>

-- 
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/baeeb802-af22-4534-93ea-378ecbc39f45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: First Django app tutorial

2018-05-14 Thread Cuneyt Mertayak
It will be a bit generic help: To understand what's going wrong with your 
code when you expect other type of behavior you can use debugging tools 
like: pdb or (if you use an IDE like pycharm) build-in IDE debugger 
(https://www.jetbrains.com/help/pycharm/debugging-django-templates.html, 
https://www.jetbrains.com/help/pycharm/debugging-django-templates.html).

I believe you'll get to the root cause of the problem faster with debugger 
use.

On Monday, May 14, 2018 at 4:02:43 AM UTC-7, Yufenyuy Veyeh Didier wrote:
>
> Hi everyone, I'm new to python and Django. I also think I am getting it 
> well. But I have an issue with the first Django app tutorial.
> My questions display well redirect to the detail view well and to the vote 
> view well. 
> The problem I have is that my question does not display the 'choices' of 
> type radio bellow the question text but displays the vote button of type 
> submit
> below is the code for the detail.html template and the image of the view 
> on my browser. 
>
> Can anyone help, please?
>
> {{ question.question_text }}
>
> {% if error_message %}{{ error_message }}{% endif 
> %}
>
> 
> {% csrf_token %}
> {% for choice in question.choice_set.all %}
> 
> {{ choice.choice_text }}<
> br />
> {% endfor %}
> 
> 
>
>
>
>
> 
>
>
>

-- 
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/5ba932a2-31b9-4adc-aa03-34015967e754%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.