Re: Django-admin problem

2018-05-04 Thread Mikko Meronen
Thank you for your help.

I also found a video that helped me with PowerShell (just if someone else
has the same problem): https://www.youtube.com/watch?v=3TqO5FfhV28


2018-05-04 21:27 GMT+03:00 Matthew Pava :

> And you’re using PowerShell instead of the command prompt.  I typically
> just work in the command prompt.  With PowerShell, you may have to be more
> explicit in your path, such as using “.\django-admin startproject mysite”
>
>
>
> *From:* django-users@googlegroups.com [mailto:django-users@
> googlegroups.com] *On Behalf Of *Jani Tiainen
> *Sent:* Friday, May 4, 2018 1:26 PM
> *To:* django-users@googlegroups.com
> *Subject:* Re: Django-admin problem
>
>
>
> Hi,
>
>
>
> By the looks of error you're running windows.
>
>
>
> By default scripts are not in PATH so you need to type something like
> c:\python36\scripts\django-admin.py
>
>
>
> Or you should use virtualenv (or pipenv) which would set path correctly.
>
>
>
> pe 4. toukokuuta 2018 klo 19.51 Mikko 
> kirjoitti:
>
> Hi,
>
>
>
> I'm trying to follow the tutorial, but I got this problem at the very
> beginning when I tried ''django-admin startproject mysite'':
>
>
>
> django-admin : The term 'django-admin' is not recognized as the name of a
> cmdlet, function, script file, or operable pr
>
> ogram. Check the spelling of the name, or if a path was included, verify
> that the path is correct and try again.
>
> At line:1 char:1
>
> + django-admin startproject mysite
>
> + 
>
> + CategoryInfo  : ObjectNotFound: (django-admin:String) [],
> CommandNotFoundException
>
> + FullyQualifiedErrorId : CommandNotFoundException
>
>
>
> Could someone help me to overcome this?
>
>
>
>
>
> --
> 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/28096273-fd67-4084-ba8a-f4e3c75d5916%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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/CAHn91odAtLj7Xc%3DChc0f7yLZ-
> HY7hiM3%3DaNSRxhY1MQd_qbREw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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/9a713a6d5e6a43e987a422e33be385e1%40ISS1.ISS.LOCAL
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGD0jjKsJpsWW58FYwK1LgPBdLWL48MLEqv55ZkQDvb2aguXRQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problem in part 6, CSS doesn't work

2018-05-26 Thread Mikko Meronen
Hi,

I can't get the CSS code to work. Link color doesn't change to green nor
the background image appear.

What could be the problem? The CSS code is in Wordpad.


polls/static/polls/images/style.css:

li a {
color: green;
}

body {
background: white url("images/background.gif") no-repeat;
}




polls/templates/polls/index.html:

{% if latest_question_list %}

{% for question in latest_question_list %}
{{
question.question_text }}
{% endfor %}

{% else %}
No polls are available.
{% endif %}

{% load static %}





Best regards,

Mikko

-- 
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/CAGD0jjK-CUUcUe9oTNqCLt%2BGTVkro2eGc12XcjiqsMj7xdZcBQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem in part 6, CSS doesn't work

2018-05-26 Thread Mikko Meronen
Hi,

Still the same problem :(

Mikko

2018-05-26 17:30 GMT+03:00 Dylan Reinhold :

> Mikko,
>   Your css file is polls/static/polls/images/style.css but you are trying
> to link to polls/style.css which would be [ olls/static/polls/style.css ]
>
> Move your style.css file one folder folder down into
> polls/static/polls/style.css
>
> Dylan
>
> On Sat, May 26, 2018 at 6:52 AM, Mikko Meronen <
> mikkovillemero...@gmail.com> wrote:
>
>> Hi,
>>
>> I can't get the CSS code to work. Link color doesn't change to green nor
>> the background image appear.
>>
>> What could be the problem? The CSS code is in Wordpad.
>>
>>
>> polls/static/polls/images/style.css:
>>
>> li a {
>> color: green;
>> }
>>
>> body {
>> background: white url("images/background.gif") no-repeat;
>> }
>>
>>
>>
>>
>> polls/templates/polls/index.html:
>>
>> {% if latest_question_list %}
>> 
>> {% for question in latest_question_list %}
>> {{
>> question.question_text }}
>> {% endfor %}
>> 
>> {% else %}
>> No polls are available.
>> {% endif %}
>>
>> {% load static %}
>>
>> 
>>
>>
>>
>> Best regards,
>>
>> Mikko
>>
>> --
>> 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/ms
>> gid/django-users/CAGD0jjK-CUUcUe9oTNqCLt%2BGTVkro2eGc12Xcjiq
>> sMj7xdZcBQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAGD0jjK-CUUcUe9oTNqCLt%2BGTVkro2eGc12XcjiqsMj7xdZcBQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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/CAHtg44D%2B-C8FyXbZGQ2704q0gtbZPk9sgeVt-M_
> uQA1bgxbrXQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAHtg44D%2B-C8FyXbZGQ2704q0gtbZPk9sgeVt-M_uQA1bgxbrXQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGD0jjLev_msRb5XKmqFdH-X9Q-C5%2BO2CjBbaFN0ZHzFS1wgyw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem in part 6, CSS doesn't work

2018-05-26 Thread Mikko Meronen
In PowerShell it says:

[26/May/2018 17:45:14] "GET /static/polls/style.css HTTP/1.1" 404 1669

2018-05-26 17:42 GMT+03:00 Mikko Meronen :

> Hi,
>
> Still the same problem :(
>
> Mikko
>
> 2018-05-26 17:30 GMT+03:00 Dylan Reinhold :
>
>> Mikko,
>>   Your css file is polls/static/polls/images/style.css but you are
>> trying to link to polls/style.css which would be [
>> olls/static/polls/style.css ]
>>
>> Move your style.css file one folder folder down into
>> polls/static/polls/style.css
>>
>> Dylan
>>
>> On Sat, May 26, 2018 at 6:52 AM, Mikko Meronen <
>> mikkovillemero...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I can't get the CSS code to work. Link color doesn't change to green nor
>>> the background image appear.
>>>
>>> What could be the problem? The CSS code is in Wordpad.
>>>
>>>
>>> polls/static/polls/images/style.css:
>>>
>>> li a {
>>> color: green;
>>> }
>>>
>>> body {
>>> background: white url("images/background.gif") no-repeat;
>>> }
>>>
>>>
>>>
>>>
>>> polls/templates/polls/index.html:
>>>
>>> {% if latest_question_list %}
>>> 
>>> {% for question in latest_question_list %}
>>> {{
>>> question.question_text }}
>>> {% endfor %}
>>> 
>>> {% else %}
>>> No polls are available.
>>> {% endif %}
>>>
>>> {% load static %}
>>>
>>> 
>>>
>>>
>>>
>>> Best regards,
>>>
>>> Mikko
>>>
>>> --
>>> 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/ms
>>> gid/django-users/CAGD0jjK-CUUcUe9oTNqCLt%2BGTVkro2eGc12Xcjiq
>>> sMj7xdZcBQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAGD0jjK-CUUcUe9oTNqCLt%2BGTVkro2eGc12XcjiqsMj7xdZcBQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> 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/ms
>> gid/django-users/CAHtg44D%2B-C8FyXbZGQ2704q0gtbZPk9sgeVt-M_u
>> QA1bgxbrXQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAHtg44D%2B-C8FyXbZGQ2704q0gtbZPk9sgeVt-M_uQA1bgxbrXQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/CAGD0jjKJs7XiPOx%2B8W0X8Uskd6GC8LeJBoCSfVd-VBW38y2ZLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem in part 6, CSS doesn't work

2018-05-29 Thread Mikko Meronen
Hi,

Thank you, but I should have those correct.

I did some googling and ran following: python manage.py collectstatic

And I got this:

Django-project\lib\site-packages\django\contrib\staticfiles\storage.py",
line 43, in path
raise ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles
app without having set the STATIC_ROOT setting to a filesystem path.

If any advices available, I would appreciate it a lot, thank you.

-Mikko

2018-05-29 10:18 GMT+03:00 s.f.wrobel via Django users <
django-users@googlegroups.com>:

> Make sure that you add the following line to your settings.py:
>
> INSTALLED_APPS = [
> 'YOUR_APP_NAME',
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> ]
>
> In your case YOUR_APP_NAME should be polls.
> Only with this line set, django looks in polls/static/polls/ for static
> (e.g .css) files.
>
> --
> 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/1ce28246-ddf6-48b2-9811-988678beb65c%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGD0jjJUHeZD2ep52j-NArHPjEibVMK3Jiiqor4O4BEuS2_gtw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem in part 6, CSS doesn't work

2018-05-30 Thread Mikko Meronen
Hi,

The css file is in .../polls/static/polls/style.css

And here is the full code of .../polls/templates/polls/index.html:

{% load static %}



{% if latest_question_list %}

{% for question in latest_question_list %}
{{
question.question_text }}
{% endfor %}

{% else %}
No polls are available.
{% endif %}



And this is the PowerShell I get when opening the webpage:

[30/May/2018 17:26:42] "GET /polls/ HTTP/1.1" 200 169
[30/May/2018 17:26:42] "GET /polls/static/polls/style.css HTTP/1.1" 404 1681
Not Found: /favicon.ico
[30/May/2018 17:26:43] "GET /favicon.ico HTTP/1.1" 404 2088


-Mikko

2018-05-30 2:16 GMT+03:00 Vijay Khemlani :

> That's only for production environments, for development you don't need to
> run that command
>
> Where did you finally put the css file and what path did you put in the
>  tag?
>
> On Tue, May 29, 2018 at 1:46 PM Mikko Meronen 
> wrote:
>
>> Hi,
>>
>> Thank you, but I should have those correct.
>>
>> I did some googling and ran following: python manage.py collectstatic
>>
>> And I got this:
>>
>> Django-project\lib\site-packages\django\contrib\staticfiles\storage.py",
>> line 43, in path
>> raise ImproperlyConfigured("You're using the staticfiles app "
>> django.core.exceptions.ImproperlyConfigured: You're using the
>> staticfiles app without having set the STATIC_ROOT setting to a filesystem
>> path.
>>
>> If any advices available, I would appreciate it a lot, thank you.
>>
>> -Mikko
>>
>> 2018-05-29 10:18 GMT+03:00 s.f.wrobel via Django users <
>> django-users@googlegroups.com>:
>>
>>> Make sure that you add the following line to your settings.py:
>>>
>>> INSTALLED_APPS = [
>>> 'YOUR_APP_NAME',
>>> 'django.contrib.admin',
>>> 'django.contrib.auth',
>>> 'django.contrib.contenttypes',
>>> 'django.contrib.sessions',
>>> 'django.contrib.messages',
>>> 'django.contrib.staticfiles',
>>> ]
>>>
>>> In your case YOUR_APP_NAME should be polls.
>>> Only with this line set, django looks in polls/static/polls/ for static
>>> (e.g .css) files.
>>>
>>> --
>>> 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/1ce28246-ddf6-48b2-9811-988678beb65c%
>>> 40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/1ce28246-ddf6-48b2-9811-988678beb65c%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> 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/CAGD0jjJUHeZD2ep52j-NArHPjEibVMK3Jiiqor4O4BEuS2_
>> gtw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAGD0jjJUHeZD2ep52j-NArHPjEibVMK3Jiiqor4O4BEuS2_gtw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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/CALn3ei2ujyB0g4fV-Ow2ogcgkv8%
> 3D_XfvK2rzHTtfPjGAyJz%3DAQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CALn3ei2ujyB0g4fV-Ow2ogcgkv8%3D_XfvK2rzHTtfPjGAyJz%3DAQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGD0jjLyHF_NCtSFRRYZ18CViNDvPb81S78%2BYcV7zKyAfSxj-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django timezone problem

2019-02-03 Thread Mikko Meronen
Hi,

Is there any easy way in Django to catch end user's local time when end
user access the webpage?

I have read django documentation and tried to google solutions, but I get
quite confused. Below you will find my code. In short the code should show
a story on my webpage what happened in the past on the current day. However
it doesn't take into account the endusers local time, and thus doesn't work
properly.


*Views.py*
from django.utils import timezone

t = timezone.now() *[This should somehow react to endusers local time]*
dm = t.strftime('%m-%d')
history = history.objects.filter(monthday__exact=dm)
historystory = random.sample(list(history), 1)
args = {'historystory':historystory}
return render(request, "news/home.html", args)

*home.html*
[in html I have just the basic things to show the content]



{% for x in historystory %}
 {{ x.title }} 
 {{ x.subtitle }} 
 {{ x.content }} 
{% endfor %}




*Settings.py*
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

You can check my webpage (http://www.topithenewsdoggy.com/) to get better
understanding what I'm doing. The part is under Additional info.

-Mikko

-- 
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/CAGD0jj%2Bh_1Pd50eE0e0zXt8P-yozqCnZeYYXTe6bj6Tt6UopxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django timezone problem

2019-02-04 Thread Mikko Meronen
Hi,

Thank you for your answer. I tried timezone.now without parentheses, but it
gave me server error. I have also tried datetime, but I face the same issue.

The issue I have:
I want people to see what happened today in the past. So I created a
database where is a story or stories what happened in the history on this
day(date). My view should be able to pick a right story from the database
based on the users timezone. If Australian visits my webpage at this
moment, he should be able to see what happened on February 5 in the past
(it's already February 5 there). However he sees what happened on February
4, because it is February 4 here (in Finland or England, not sure what
timezone I'm using). So I want to make my view to understand the end user's
local time, so it can pick the right story from the database for the
webpage visitor.

-Mikko

ma 4. helmik. 2019 klo 10.15 'Amitesh Sahay' via Django users (
django-users@googlegroups.com) kirjoitti:

> Hello Mikko,
>
> There are basically two ways which I know . One is the timezone module
> that you are using another is datetime module. I believe that timezone
> module is more effective one.
> But instead of calling timezone.now() , call timezone.now.
>
> Or what is the exact issue are you facing?
>
> Regards,
> Amitesh Sahay
> *91-750 797 8619*
>
>
> On Monday, 4 February, 2019, 12:30:07 AM IST, Mikko Meronen <
> mikkovillemero...@gmail.com> wrote:
>
>
> Hi,
>
> Is there any easy way in Django to catch end user's local time when end
> user access the webpage?
>
> I have read django documentation and tried to google solutions, but I get
> quite confused. Below you will find my code. In short the code should show
> a story on my webpage what happened in the past on the current day. However
> it doesn't take into account the endusers local time, and thus doesn't work
> properly.
>
>
> *Views.py*
> from django.utils import timezone
>
> t = timezone.now() *[This should somehow react to endusers local
> time]*
> dm = t.strftime('%m-%d')
> history = history.objects.filter(monthday__exact=dm)
> historystory = random.sample(list(history), 1)
> args = {'historystory':historystory}
> return render(request, "news/home.html", args)
>
> *home.html*
> [in html I have just the basic things to show the content]
>
> 
> 
> {% for x in historystory %}
>  {{ x.title }} 
>  {{ x.subtitle }} 
>  {{ x.content }} 
> {% endfor %}
> 
> 
>
>
> *Settings.py*
> LANGUAGE_CODE = 'en-us'
> TIME_ZONE = 'UTC'
> USE_I18N = True
> USE_L10N = True
> USE_TZ = True
>
> You can check my webpage (http://www.topithenewsdoggy.com/) to get better
> understanding what I'm doing. The part is under Additional info.
>
> -Mikko
>
> --
> 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/CAGD0jj%2Bh_1Pd50eE0e0zXt8P-yozqCnZeYYXTe6bj6Tt6UopxA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAGD0jj%2Bh_1Pd50eE0e0zXt8P-yozqCnZeYYXTe6bj6Tt6UopxA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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/383150814.2310524.1549268121893%40mail.yahoo.com
> <https://groups.google.com/d/msgid/django-users/383150814.2310524.1549268121893%40mail.yahoo.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGD0jjLXV%2BxwMtjE3BSd8aAiVPuePJXLV%2BKaTQZr%2B-78udz4fQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django timezone problem

2019-02-06 Thread Mikko Meronen
Hi,

Thank you for your help :)

-Mikko

ke 6.2.2019 klo 18.47 Andréas Kühne  kirjoitti:

> Hi Mikko,
>
> The best way to do this is actually to set the timezone for the user via a
> property on the user. The reason for this is that there is no way to
> actually get the timezone from the browser (at least not completely
> correctly). That being said, if you want to go down that route - try
> something like this: https://github.com/adamcharnock/django-tz-detect
>
> What it does is use javascript to get the timezone (which doesn't always
> return the right timezone) and then uses a middleware to set the timezone
> for the current user. That way you will get the information in the correct
> timezone for the user according to the browser (which might not be correct).
>
> Regards,
>
> Andréas
>
>
> Den mån 4 feb. 2019 kl 15:04 skrev Mikko Meronen <
> mikkovillemero...@gmail.com>:
>
>> Hi,
>>
>> Thank you for your answer. I tried timezone.now without parentheses, but
>> it gave me server error. I have also tried datetime, but I face the same
>> issue.
>>
>> The issue I have:
>> I want people to see what happened today in the past. So I created a
>> database where is a story or stories what happened in the history on this
>> day(date). My view should be able to pick a right story from the database
>> based on the users timezone. If Australian visits my webpage at this
>> moment, he should be able to see what happened on February 5 in the past
>> (it's already February 5 there). However he sees what happened on February
>> 4, because it is February 4 here (in Finland or England, not sure what
>> timezone I'm using). So I want to make my view to understand the end user's
>> local time, so it can pick the right story from the database for the
>> webpage visitor.
>>
>> -Mikko
>>
>> ma 4. helmik. 2019 klo 10.15 'Amitesh Sahay' via Django users (
>> django-users@googlegroups.com) kirjoitti:
>>
>>> Hello Mikko,
>>>
>>> There are basically two ways which I know . One is the timezone module
>>> that you are using another is datetime module. I believe that timezone
>>> module is more effective one.
>>> But instead of calling timezone.now() , call timezone.now.
>>>
>>> Or what is the exact issue are you facing?
>>>
>>> Regards,
>>> Amitesh Sahay
>>> *91-750 797 8619*
>>>
>>>
>>> On Monday, 4 February, 2019, 12:30:07 AM IST, Mikko Meronen <
>>> mikkovillemero...@gmail.com> wrote:
>>>
>>>
>>> Hi,
>>>
>>> Is there any easy way in Django to catch end user's local time when end
>>> user access the webpage?
>>>
>>> I have read django documentation and tried to google solutions, but I
>>> get quite confused. Below you will find my code. In short the code should
>>> show a story on my webpage what happened in the past on the current day.
>>> However it doesn't take into account the endusers local time, and thus
>>> doesn't work properly.
>>>
>>>
>>> *Views.py*
>>> from django.utils import timezone
>>>
>>> t = timezone.now() *[This should somehow react to endusers local
>>> time]*
>>> dm = t.strftime('%m-%d')
>>> history = history.objects.filter(monthday__exact=dm)
>>> historystory = random.sample(list(history), 1)
>>> args = {'historystory':historystory}
>>> return render(request, "news/home.html", args)
>>>
>>> *home.html*
>>> [in html I have just the basic things to show the content]
>>>
>>> 
>>> 
>>> {% for x in historystory %}
>>>  {{ x.title }} 
>>>  {{ x.subtitle }} 
>>>  {{ x.content }} 
>>> {% endfor %}
>>> 
>>> 
>>>
>>>
>>> *Settings.py*
>>> LANGUAGE_CODE = 'en-us'
>>> TIME_ZONE = 'UTC'
>>> USE_I18N = True
>>> USE_L10N = True
>>> USE_TZ = True
>>>
>>> You can check my webpage (http://www.topithenewsdoggy.com/) to get
>>> better understanding what I'm doing. The part is under Additional info.
>>>
>>> -Mikko
>>>
>>> --
>>> 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

Re: Django template

2019-02-08 Thread Mikko Meronen
Hi,

Have to say that Im still beginner in Django and coding, but I think you
just create you html files to your templates folder, and in the end you are
basically using just html. Django can just find your html file from
templates folder.

Im just learning javascript and I assume i can save my js-file to templates
folder as well and connect it to my html.

-Mikko

pe 8.2.2019 klo 21.07 Tom Zhang  kirjoitti:

> Hi, all,
>
> If I don't want to use Django template engine and I just want to use
> regular html/javacript, how do I configure settings.py?
> I am thinking about the portability issue. For example, if I want to move
> away from django in the future, I hope my templates can still be used in
> other frameworks, at least, with minimum changes.
> My settings are:
>
> TEMPLATES = [
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': [os.path.join(BASE_DIR, 'templates')],
> 'APP_DIRS': True,
> 'OPTIONS': {
> 'context_processors': [
> 'django.template.context_processors.debug',
> 'django.template.context_processors.request',
> 'django.contrib.auth.context_processors.auth',
> 'django.contrib.messages.context_processors.messages',
> ],
> },
> },
> ]
>
> Thanks,
>
> Tom
>
> --
> 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/237d37a9-a913-430c-8861-eeedb8f6bece%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGD0jjJju_32dqxzuz56z1EUqPnGirQFMFgn0RPOP_qWEGznPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django timezone problem

2019-02-08 Thread Mikko Meronen
Hi Alvaro,

If I do that (JS and AJAX), do you think my views.py is already correct? *T
= timezone.now()* is important for me in order to get the right data from
sql for the end user.

*Views.py*
from django.utils import timezone

*t = timezone.now()* [this should detect end user's timezone]
dm = t.strftime('%m-%d')
history = history.objects.filter(monthday__exact=dm)
historystory = random.sample(list(history), 1)
args = {'historystory':historystory}
return render(request, "news/home.html", args)

-Mikko

-Mikko

pe 8.2.2019 klo 22.04 Alvaro Chen  kirjoitti:

> Set the timezone for the user via a property on the user is the best way.
> Otherwise, JS can detect the user's time zone. Use moment.js (
> https://momentjs.com/timezone/docs/#/using-timezones/guessing-user-timezone/)
> or Intl (
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
> ).
>
> In my project, JS sends an AJAX request to Django with timezone when
> anonymous users access the webpage. Save timezone in request.session.
>
> from django.utils import timezone
> ​
> import pytz
> ​
> # Set user's timezone
> tzinfo = pytz.timezone(request.session['timezone']) 
> #request.session['timezone'] = 'America/Los_Angeles'
> timezone.activate(tzinfo)
> timezone.localtime(timezone.now()).isoformat()
> ​
> # Resume default timezone (setting.py # TIME_ZONE)
> timezone.deactivate()
> timezone.localtime(timezone.now()).isoformat()
>
> Hope this helps.
>
> BR,
>
> Alvaro
>
> On Wednesday, February 6, 2019 at 12:25:45 PM UTC-8, Mikko wrote:
>>
>> Hi,
>>
>> Thank you for your help :)
>>
>> -Mikko
>>
>> ke 6.2.2019 klo 18.47 Andréas Kühne  kirjoitti:
>>
>>> Hi Mikko,
>>>
>>> The best way to do this is actually to set the timezone for the user via
>>> a property on the user. The reason for this is that there is no way to
>>> actually get the timezone from the browser (at least not completely
>>> correctly). That being said, if you want to go down that route - try
>>> something like this: https://github.com/adamcharnock/django-tz-detect
>>>
>>> What it does is use javascript to get the timezone (which doesn't always
>>> return the right timezone) and then uses a middleware to set the timezone
>>> for the current user. That way you will get the information in the correct
>>> timezone for the user according to the browser (which might not be correct).
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>>
>>> Den mån 4 feb. 2019 kl 15:04 skrev Mikko Meronen >> >:
>>>
>>>> Hi,
>>>>
>>>> Thank you for your answer. I tried timezone.now without parentheses,
>>>> but it gave me server error. I have also tried datetime, but I face the
>>>> same issue.
>>>>
>>>> The issue I have:
>>>> I want people to see what happened today in the past. So I created a
>>>> database where is a story or stories what happened in the history on this
>>>> day(date). My view should be able to pick a right story from the database
>>>> based on the users timezone. If Australian visits my webpage at this
>>>> moment, he should be able to see what happened on February 5 in the past
>>>> (it's already February 5 there). However he sees what happened on February
>>>> 4, because it is February 4 here (in Finland or England, not sure what
>>>> timezone I'm using). So I want to make my view to understand the end user's
>>>> local time, so it can pick the right story from the database for the
>>>> webpage visitor.
>>>>
>>>> -Mikko
>>>>
>>>> ma 4. helmik. 2019 klo 10.15 'Amitesh Sahay' via Django users (
>>>> django...@googlegroups.com) kirjoitti:
>>>>
>>>>> Hello Mikko,
>>>>>
>>>>> There are basically two ways which I know . One is the timezone module
>>>>> that you are using another is datetime module. I believe that timezone
>>>>> module is more effective one.
>>>>> But instead of calling timezone.now() , call timezone.now.
>>>>>
>>>>> Or what is the exact issue are you facing?
>>>>>
>>>>> Regards,
>>>>> Amitesh Sahay
>>>>> *91-750 797 8619*
>>>>>
>>>>>
>>>>> On Monday, 4 February, 2019, 12:30:07 AM IST, Mikko Meronen <
>>>>> m

Re: Django timezone problem

2019-02-08 Thread Mikko Meronen
Hi,

But if  I get the visitor's timezone using JS and send it to Django using
AJAX and also do the changes below Alvaro suggested:

from django.utils import timezone

import pytz

# Set user's timezone
tzinfo = pytz.timezone(request.session['timezone'])
#request.session['timezone'] = 'America/Los_Angeles'
timezone.activate(tzinfo)
timezone.localtime(timezone.now()).isoformat()

# Resume default timezone (setting.py # TIME_ZONE)
timezone.deactivate()
timezone.localtime(timezone.now()).isoformat()


Do you think it should then be alright and my timezone.now() function works?

-Mikko



pe 8. helmik. 2019 klo 23.10 Josiah Jenson Nawaya (nawayajos...@gmail.com)
kirjoitti:

> Hi, i believe what the system do with your timezone.now() function call is
> ton currently get the timezone of the location where your server is
> located. So if your hosting server is in England, it gets the server
> location timezone. U will need to first find a way to get the visitors
> location and get the  timezone at that location. Hope it helps
>
> On Fri, Feb 8, 2019, 9:04 PM Alvaro Chen 
>> Set the timezone for the user via a property on the user is the best way.
>> Otherwise, JS can detect the user's time zone. Use moment.js (
>> https://momentjs.com/timezone/docs/#/using-timezones/guessing-user-timezone/)
>> or Intl (
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
>> ).
>>
>> In my project, JS sends an AJAX request to Django with timezone when
>> anonymous users access the webpage. Save timezone in request.session.
>>
>> from django.utils import timezone
>> ​
>> import pytz
>> ​
>> # Set user's timezone
>> tzinfo = pytz.timezone(request.session['timezone']) 
>> #request.session['timezone'] = 'America/Los_Angeles'
>> timezone.activate(tzinfo)
>> timezone.localtime(timezone.now()).isoformat()
>> ​
>> # Resume default timezone (setting.py # TIME_ZONE)
>> timezone.deactivate()
>> timezone.localtime(timezone.now()).isoformat()
>>
>> Hope this helps.
>>
>> BR,
>>
>> Alvaro
>>
>> On Wednesday, February 6, 2019 at 12:25:45 PM UTC-8, Mikko wrote:
>>>
>>> Hi,
>>>
>>> Thank you for your help :)
>>>
>>> -Mikko
>>>
>>> ke 6.2.2019 klo 18.47 Andréas Kühne  kirjoitti:
>>>
>>>> Hi Mikko,
>>>>
>>>> The best way to do this is actually to set the timezone for the user
>>>> via a property on the user. The reason for this is that there is no way to
>>>> actually get the timezone from the browser (at least not completely
>>>> correctly). That being said, if you want to go down that route - try
>>>> something like this: https://github.com/adamcharnock/django-tz-detect
>>>>
>>>> What it does is use javascript to get the timezone (which doesn't
>>>> always return the right timezone) and then uses a middleware to set the
>>>> timezone for the current user. That way you will get the information in the
>>>> correct timezone for the user according to the browser (which might not be
>>>> correct).
>>>>
>>>> Regards,
>>>>
>>>> Andréas
>>>>
>>>>
>>>> Den mån 4 feb. 2019 kl 15:04 skrev Mikko Meronen >>> >:
>>>>
>>>>> Hi,
>>>>>
>>>>> Thank you for your answer. I tried timezone.now without parentheses,
>>>>> but it gave me server error. I have also tried datetime, but I face the
>>>>> same issue.
>>>>>
>>>>> The issue I have:
>>>>> I want people to see what happened today in the past. So I created a
>>>>> database where is a story or stories what happened in the history on this
>>>>> day(date). My view should be able to pick a right story from the database
>>>>> based on the users timezone. If Australian visits my webpage at this
>>>>> moment, he should be able to see what happened on February 5 in the past
>>>>> (it's already February 5 there). However he sees what happened on February
>>>>> 4, because it is February 4 here (in Finland or England, not sure what
>>>>> timezone I'm using). So I want to make my view to understand the end 
>>>>> user's
>>>>> local time, so it can pick the right story from the database for the
>>>>> webpage visitor.
>>>>>
>>>>> -Mikko
>>

Re: Django template

2019-02-08 Thread Mikko Meronen
Hi,

You can connect your backend to frontend using views.py file. In views.py
you can get and sort your data from SQL and send it to your html.

You probably should do tutorial or watch youtube videos (as I did since I
get bored in reading very fast) to learn more. CodingEntrepreneur has done
quite up to date videos, though you might need to check some point from
tutorial sheets as well.
Here is a link to backend-frontend video, but better to see the series from
the beginning when you are new:

https://www.youtube.com/watch?v=h05UEays2KI&list=PLEsfXFp6DpzTD1BD1aWNxS2Ep06vIkaeW&index=17

My example from views.py, where I get and sort data from my database and
connect it to my webpage. In your html you need some code to get the data
from views.py.

*views.py*

from django.shortcuts import render
from .models import news

def Home(request):
worlddata =
news.objects.filter(subsection__exact='World').order_by('-created')[:8]
args = {'worlddata': worlddata}
return render(request, "news/home.html", args)

In* home.html* (bolded ones is the code you need to connect to your
views.py)

*{% for news in worlddata %}*
 *{{ news.title }}* 
*{% endfor %}*

-Mikko


la 9. helmik. 2019 klo 8.15 Tom Zhang (computerset...@gmail.com) kirjoitti:

> Thanks. But if I do this way, how do I transfer data between back-end and
> front-end? Do I use post request?
>
>
> On Friday, February 8, 2019 at 8:35:28 PM UTC-5, Nitin Kalmaste wrote:
>>
>> You are correct,
>> You are using HTML and JavaScript as template in django. You need to
>> store static files like css/images/JavaScript in static folder and
>> configure static folder in the settings file
>>
>> On Sat, Feb 9, 2019, 1:00 AM Mikko Meronen >
>>> Hi,
>>>
>>> Have to say that Im still beginner in Django and coding, but I think you
>>> just create you html files to your templates folder, and in the end you are
>>> basically using just html. Django can just find your html file from
>>> templates folder.
>>>
>>> Im just learning javascript and I assume i can save my js-file to
>>> templates folder as well and connect it to my html.
>>>
>>> -Mikko
>>>
>>> pe 8.2.2019 klo 21.07 Tom Zhang  kirjoitti:
>>>
>>>> Hi, all,
>>>>
>>>> If I don't want to use Django template engine and I just want to use
>>>> regular html/javacript, how do I configure settings.py?
>>>> I am thinking about the portability issue. For example, if I want to
>>>> move away from django in the future, I hope my templates can still be used
>>>> in other frameworks, at least, with minimum changes.
>>>> My settings are:
>>>>
>>>> TEMPLATES = [
>>>> {
>>>> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
>>>> 'DIRS': [os.path.join(BASE_DIR, 'templates')],
>>>> 'APP_DIRS': True,
>>>> 'OPTIONS': {
>>>> 'context_processors': [
>>>> 'django.template.context_processors.debug',
>>>> 'django.template.context_processors.request',
>>>> 'django.contrib.auth.context_processors.auth',
>>>> 'django.contrib.messages.context_processors.messages',
>>>> ],
>>>> },
>>>> },
>>>> ]
>>>>
>>>> Thanks,
>>>>
>>>> Tom
>>>>
>>>> --
>>>> 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...@googlegroups.com.
>>>> To post to this group, send email to django...@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/237d37a9-a913-430c-8861-eeedb8f6bece%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/237d37a9-a913-430c-8861-eeedb8f6bece%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To

Re: Django template

2019-02-08 Thread Mikko Meronen
Hi,

I haven't used any other framework, so maybe someone else can better answer
that. But using my logic I think that if I want to change framework, I just
have to know how to connect again my database to my html, which is just to
learn the new framework logic I guess. But as I said, hopefully someone
wiser can answer to this :p

-Mikko

la 9. helmik. 2019 klo 8.48 Tom Zhang (computerset...@gmail.com) kirjoitti:

> Thanks. I know how to do this according to Django way. But if you use
> Django's way to transfer data, it makes it difficult to move to other
> frameworks, right? What do you think?
>
> On Saturday, February 9, 2019 at 1:42:19 AM UTC-5, Mikko wrote:
>>
>> Hi,
>>
>> You can connect your backend to frontend using views.py file. In views.py
>> you can get and sort your data from SQL and send it to your html.
>>
>> You probably should do tutorial or watch youtube videos (as I did since I
>> get bored in reading very fast) to learn more. CodingEntrepreneur has done
>> quite up to date videos, though you might need to check some point from
>> tutorial sheets as well.
>> Here is a link to backend-frontend video, but better to see the series
>> from the beginning when you are new:
>>
>>
>> https://www.youtube.com/watch?v=h05UEays2KI&list=PLEsfXFp6DpzTD1BD1aWNxS2Ep06vIkaeW&index=17
>>
>> My example from views.py, where I get and sort data from my database and
>> connect it to my webpage. In your html you need some code to get the data
>> from views.py.
>>
>> *views.py*
>>
>> from django.shortcuts import render
>> from .models import news
>>
>> def Home(request):
>> worlddata =
>> news.objects.filter(subsection__exact='World').order_by('-created')[:8]
>> args = {'worlddata': worlddata}
>> return render(request, "news/home.html", args)
>>
>> In* home.html* (bolded ones is the code you need to connect to your
>> views.py)
>>
>> *{% for news in worlddata %}*
>>  *{{ news.title }}*
>> 
>> *{% endfor %}*
>>
>> -Mikko
>>
>>
>> la 9. helmik. 2019 klo 8.15 Tom Zhang (compute...@gmail.com) kirjoitti:
>>
>>> Thanks. But if I do this way, how do I transfer data between back-end
>>> and front-end? Do I use post request?
>>>
>>>
>>> On Friday, February 8, 2019 at 8:35:28 PM UTC-5, Nitin Kalmaste wrote:
>>>>
>>>> You are correct,
>>>> You are using HTML and JavaScript as template in django. You need to
>>>> store static files like css/images/JavaScript in static folder and
>>>> configure static folder in the settings file
>>>>
>>>> On Sat, Feb 9, 2019, 1:00 AM Mikko Meronen >>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> Have to say that Im still beginner in Django and coding, but I think
>>>>> you just create you html files to your templates folder, and in the end 
>>>>> you
>>>>> are basically using just html. Django can just find your html file from
>>>>> templates folder.
>>>>>
>>>>> Im just learning javascript and I assume i can save my js-file to
>>>>> templates folder as well and connect it to my html.
>>>>>
>>>>> -Mikko
>>>>>
>>>>> pe 8.2.2019 klo 21.07 Tom Zhang  kirjoitti:
>>>>>
>>>>>> Hi, all,
>>>>>>
>>>>>> If I don't want to use Django template engine and I just want to use
>>>>>> regular html/javacript, how do I configure settings.py?
>>>>>> I am thinking about the portability issue. For example, if I want to
>>>>>> move away from django in the future, I hope my templates can still be 
>>>>>> used
>>>>>> in other frameworks, at least, with minimum changes.
>>>>>> My settings are:
>>>>>>
>>>>>> TEMPLATES = [
>>>>>> {
>>>>>> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
>>>>>> 'DIRS': [os.path.join(BASE_DIR, 'templates')],
>>>>>> 'APP_DIRS': True,
>>>>>> 'OPTIONS': {
>>>>>> 'context_processors': [
>>>>>> 'django.template.context_processors.debug',
>>>>>> 'django.template.context_

Django database problem

2018-08-17 Thread Mikko Meronen
Hi,

I'm quite new with django and python and I wish someone could help me.

I'm building a webpage where my python program/bot collects data from
webpages.

Is there a way that I can use my python program to store the data to
django's database?

At the moment when I run my program, I collect the data to separate sqlite
database, but I don't know how to collect/connect it to django's sqlite
database (or models).

- Mikko

-- 
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/CAGD0jjLbzK1XVVSUTD4Z66p_RUoK0pBW%2BrEYtVM_HwAd9d%3DwvQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django database problem

2018-08-20 Thread Mikko Meronen
Hi and thanks for your help.

I have tried postgress and now I have a problem using it. Here's my code
following an error. I appreciate any help.

def do():
x = 1
while x == 1:
create_table()
print('finding data')
find_data()
time.sleep(120)

def create_table():
c.execute('CREATE TABLE IF NOT EXISTS testi(url TEXT, title TEXT,
published TEXT, UNIQUE(url))')

def find_data():
r = requests.get(homepage)
soup = BeautifulSoup(r.text, 'html.parser')
results = soup.find_all('data')
for result in results:
title = result.find('h1').text
url = result.find('a')['href']
published = result.find('time')['datetime']


c.execute("INSERT OR IGNORE INTO testi (url, title,
published) VALUES (%s, %s, %s)",
  ('url', 'title', 'published'))
connection.commit()


do()

ERROR:

Traceback (most recent call last):
  File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 43, in

do()
  File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 21, in
do
find_data()
  File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 39, in
find_data
('url', 'title', 'published'))
*psycopg2.ProgrammingError: syntax error at or near "OR"*
*LINE 1: INSERT OR IGNORE INTO testi (url, title, published) VALUES (...*



-Mikko


2018-08-17 19:09 GMT+03:00 Mikhailo Keda :

> You could generate models from sqlite database -
> https://docs.djangoproject.com/en/2.1/howto/legacy-databases/
> Than switch to PostgresQL
>
> --
> 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/52f5c754-7310-4baa-8008-edbcea15eafb%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGD0jjJof7v9nMPF593DJiQHRv6z_%3DmQ_ZtQWob47PBT1gvL9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django database problem

2018-08-26 Thread Mikko Meronen
Hi,

Thanks for advice ^^

I have one new concern. Is there a limit for for Django model IDs?

Now I have automated the data insert with python code loop, but the
ID-number is not consecutive. It jumps for example from ...56 to 571... and
from ...587 to 3763... and so forth.

Do you know why it is doing that?

I'm not using django custom command (if that makes the difference or can be
used for my case, I will get familiar with it a bit later), I'm just
inserting the data to django's database with separate python code.

-Mikko

ma 20. elok. 2018 klo 20.41 Jani Tiainen (rede...@gmail.com) kirjoitti:

> Hi,
>
> Instead of doing everything by hand I would recommend doing a custom
> management command in Django.
>
> Because management commands live inside Django ecosystem you get full
> benefits of Django. Migrations to setup database tables from model
> definitions. Models and ORM to interact with database. (Model)forms to
> validate your incoming data etc.
>
> Also I really suggest that you do the official tutorial from the docs to
> get hang of basic django concepts.
>
> ma 20. elok. 2018 klo 19.59 Mikko Meronen 
> kirjoitti:
>
>> Hi and thanks for your help.
>>
>> I have tried postgress and now I have a problem using it. Here's my code
>> following an error. I appreciate any help.
>>
>> def do():
>> x = 1
>> while x == 1:
>> create_table()
>> print('finding data')
>> find_data()
>> time.sleep(120)
>>
>> def create_table():
>> c.execute('CREATE TABLE IF NOT EXISTS testi(url TEXT, title TEXT,
>> published TEXT, UNIQUE(url))')
>>
>> def find_data():
>> r = requests.get(homepage)
>> soup = BeautifulSoup(r.text, 'html.parser')
>> results = soup.find_all('data')
>> for result in results:
>> title = result.find('h1').text
>> url = result.find('a')['href']
>> published = result.find('time')['datetime']
>>
>>
>> c.execute("INSERT OR IGNORE INTO testi (url, title,
>> published) VALUES (%s, %s, %s)",
>>   ('url', 'title', 'published'))
>> connection.commit()
>>
>>
>> do()
>>
>> ERROR:
>>
>> Traceback (most recent call last):
>>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 43,
>> in 
>> do()
>>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 21,
>> in do
>> find_data()
>>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 39,
>> in find_data
>> ('url', 'title', 'published'))
>> *psycopg2.ProgrammingError: syntax error at or near "OR"*
>> *LINE 1: INSERT OR IGNORE INTO testi (url, title, published) VALUES (...*
>>
>>
>>
>> -Mikko
>>
>>
>> 2018-08-17 19:09 GMT+03:00 Mikhailo Keda :
>>
>>> You could generate models from sqlite database -
>>> https://docs.djangoproject.com/en/2.1/howto/legacy-databases/
>>> Than switch to PostgresQL
>>>
>>> --
>>> 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/52f5c754-7310-4baa-8008-edbcea15eafb%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/52f5c754-7310-4baa-8008-edbcea15eafb%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> 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
>> htt

Re: Django database problem

2018-08-27 Thread Mikko Meronen
Yes it seems that I can influence to the 'jumps' with my management
command. First my bot went through tens of items per loop, however when I
changed the bot to check only 2 items per loop, the 'jumps' got smaller. So
even though the table rows do not accrue (nothing is added) when no new
items are found in a loop, the ID numbers still accrue behind the scenes in
every loop.

So I just gotta figure out if there are any other way than INSERT OR IGNORE
command, or just decrease the sleep time of the bot and keep the checked
item numbers low per a loop.

I actually tried ROLLBACK and some other commands as well, but they killed
the loop.

Thanks for the help ^^

-Mikko


ma 27. elok. 2018 klo 15.01 Andréas Kühne (andreas.ku...@hypercode.se)
kirjoitti:

> I have looked at this several times myself. :-)
>
> Regards,
>
> Andréas
>
>
> Den mån 27 aug. 2018 kl 13:33 skrev Jason :
>
>> oh, good catch.  I didn't think of that, but you're right.
>>
>>
>> https://stackoverflow.com/questions/449346/mysql-auto-increment-does-not-rollback
>>
>> On Monday, August 27, 2018 at 3:50:28 AM UTC-4, Andréas Kühne wrote:
>>>
>>> The management command could be wrapped within a transaction, this would
>>> then in the database create a lot of models, but if the transaction fails -
>>> the rollback will not reset the database id.
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>>
>>> Den sön 26 aug. 2018 kl 12:29 skrev Mikko Meronen >> >:
>>>
>>>> Hi,
>>>>
>>>> Thanks for advice ^^
>>>>
>>>> I have one new concern. Is there a limit for for Django model IDs?
>>>>
>>>> Now I have automated the data insert with python code loop, but the
>>>> ID-number is not consecutive. It jumps for example from ...56 to 571... and
>>>> from ...587 to 3763... and so forth.
>>>>
>>>> Do you know why it is doing that?
>>>>
>>>> I'm not using django custom command (if that makes the difference or
>>>> can be used for my case, I will get familiar with it a bit later), I'm just
>>>> inserting the data to django's database with separate python code.
>>>>
>>>> -Mikko
>>>>
>>>> ma 20. elok. 2018 klo 20.41 Jani Tiainen (red...@gmail.com) kirjoitti:
>>>>
>>>>> Hi,
>>>>>
>>>>> Instead of doing everything by hand I would recommend doing a custom
>>>>> management command in Django.
>>>>>
>>>>> Because management commands live inside Django ecosystem you get full
>>>>> benefits of Django. Migrations to setup database tables from model
>>>>> definitions. Models and ORM to interact with database. (Model)forms to
>>>>> validate your incoming data etc.
>>>>>
>>>>> Also I really suggest that you do the official tutorial from the docs
>>>>> to get hang of basic django concepts.
>>>>>
>>>>> ma 20. elok. 2018 klo 19.59 Mikko Meronen 
>>>>> kirjoitti:
>>>>>
>>>>>> Hi and thanks for your help.
>>>>>>
>>>>>> I have tried postgress and now I have a problem using it. Here's my
>>>>>> code following an error. I appreciate any help.
>>>>>>
>>>>>> def do():
>>>>>> x = 1
>>>>>> while x == 1:
>>>>>> create_table()
>>>>>> print('finding data')
>>>>>> find_data()
>>>>>> time.sleep(120)
>>>>>>
>>>>>> def create_table():
>>>>>> c.execute('CREATE TABLE IF NOT EXISTS testi(url TEXT, title TEXT,
>>>>>> published TEXT, UNIQUE(url))')
>>>>>>
>>>>>> def find_data():
>>>>>> r = requests.get(homepage)
>>>>>> soup = BeautifulSoup(r.text, 'html.parser')
>>>>>> results = soup.find_all('data')
>>>>>> for result in results:
>>>>>> title = result.find('h1').text
>>>>>> url = result.find('a')['href']
>>>>>> published = result.find('time')['datetime']
>>>>>>
>>>>>>
>>>>>> c.

Views & Template issue

2018-09-09 Thread Mikko Meronen
Hi again,

I'm trying to include two views in one html template, however the
latter(bolded) view doesn't work.

The first one works well and I can see the items created within last 15
minutes in my webpage. However when I want to see the older items (bolded
html part and index1 in views.py), I don't get anything, not even an error.
Do I need to add something to other files in Django or is this even
possible?

- Mikko



{% for news in newstest %}
 {{ news.title }} 
{{ news.publisher }} {{ news.section }} {{ news.country }}

{% endfor %}

 +15 min 

*{% for news in newstest1 %}*
*  {{ news.title }} *
* {{ news.publisher }} {{ news.section }} {{ news.country }}*
* *
* {% endfor %}*





def index(request):
newstest = NewsData.objects.filter(created__gt= time.time() -
900).order_by('-created')
args = {'newstest': newstest}
return render(request, "news/index.html", args)

def index1(request):
newstest1 = NewsData.objects.filter(created__lt= time.time() -
900).order_by('-created')
args1 = {'newstest1': newstest1}
return render(request, "news/index.html", args1)

-- 
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/CAGD0jjLmhg2SzTb6oCtapBK_h4AN5_zCUdsj7ntHGfteqiRFvA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Views & Template issue

2018-09-09 Thread Mikko Meronen
Thank you.

-Mikko

su 9. syysk. 2018 klo 16.49 Jason (jjohns98...@gmail.com) kirjoitti:

> You've defined two views which pass in different querysets to be rendered.
>
> so if you hit index, you get the first queryset rendered but not the
> second because newstest1 is not rendered at all.  and vice versa.
>
> solution is to add newstest1 to index and pass both querysets as context
> to the render.  eg
>
> return render(request, 'news/index.html', {'newstest': newstest,
> 'newstest1': newstest1})
>
> --
> 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/6ebc2322-5bb5-4809-a6f3-1adf94e92168%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGD0jjJXo8_Qe%2Bq9OWrYKC3zbzP%3DFj-S59SGNo%2ByvqehWqm0_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Views & Template issue

2018-09-11 Thread Mikko Meronen
Hi, I still have a small issue here and couldn't figure it out.

I want to divide my items based on the time created. The division point is
5 minutes and  I want that point to be seen in my webpage. However when I
made the division point, Django doesn't update it (the items that become
older than 5 mins do not move to the older group) until I restart the
server. Otherwise the new items will aggregate to the webpage as supposed.
Is there anyway in Django to make this work in views.py and templates?

Otherwise I guess I should try to figure out if it is possible in SQL side
by creating more tables based on the creation time and updating the tables
there. Now all my items are in a single table.

- Mikko

t = time.time()

def index(request):
newstest = NewsData.objects.filter(created__gt= t -
300).order_by('-created')
newstest1 = NewsData.objects.filter(created__lt= t -
300).order_by('-created')
args = {'newstest': newstest, 'newstest1':newstest1,* 'newstest2':['Older
than 5 min']*}
return render(request, "news/index.html", args)






{% for news in newstest %}
 {{ news.title }} 
{{ news.published }} {{ news.publisher }} {{ news.section }} {{
news.country }}

{% endfor %}




**
* *
* *
* *
* {% for c in newstest2 %}*
*  {{c}} *
* *
* {% endfor %}*
* *
* *
* *
* *





{% for news1 in newstest1 %}
 {{ news1.title }} 
{{ news1.published }} {{ news1.publisher }} {{ news1.section }} {{
news1.country }}

{% endfor %}





su 9. syysk. 2018 klo 17.21 Mikko Meronen (mikkovillemero...@gmail.com)
kirjoitti:

> Thank you.
>
> -Mikko
>
> su 9. syysk. 2018 klo 16.49 Jason (jjohns98...@gmail.com) kirjoitti:
>
>> You've defined two views which pass in different querysets to be rendered.
>>
>> so if you hit index, you get the first queryset rendered but not the
>> second because newstest1 is not rendered at all.  and vice versa.
>>
>> solution is to add newstest1 to index and pass both querysets as context
>> to the render.  eg
>>
>> return render(request, 'news/index.html', {'newstest': newstest,
>> 'newstest1': newstest1})
>>
>> --
>> 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/6ebc2322-5bb5-4809-a6f3-1adf94e92168%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/6ebc2322-5bb5-4809-a6f3-1adf94e92168%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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/CAGD0jjLOtkTd2PRpM38Z_ypUDJ%2BeEmXcSz640EU_qn1kjMeuFw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Views & Template issue

2018-09-12 Thread Mikko Meronen
Thank you, works well now :)

ke 12. syysk. 2018 klo 11.37 Andréas Kühne (andreas.ku...@hypercode.se)
kirjoitti:

> Hi Mikko,
>
> It works correctly the way you have written it. Look at the code you have
> written:
> t = time.time()
>
> def index(request):
> newstest = NewsData.objects.filter(created__gt= t -
> 300).order_by('-created')
> newstest1 = NewsData.objects.filter(created__lt= t -
> 300).order_by('-created')
> args = {'newstest': newstest, 'newstest1':newstest1,* 'newstest2':['Older
> than 5 min']*}
>
>
> You get the time when the server is started (the time.time() function is
> only run once) and then you never call that function again.
> If you want to check the time every time you load the page you should do
> it like this:
>
> def index(request):
> t = time.time()
> newstest = NewsData.objects.filter(created__gt= t -
> 300).order_by('-created')
> newstest1 = NewsData.objects.filter(created__lt= t -
> 300).order_by('-created')
> args = {'newstest': newstest, 'newstest1':newstest1,* 'newstest2':['Older
> than 5 min']*}
>
> Also you should not use the basic time fileds in python when querying the
> database, but use fields that include the current timezone. In that case
> you should add this instead:
>
> from django.utils.timezone import now
>
> def index(request):
> t = now()
> newstest = NewsData.objects.filter(created__gt= t -
> 300).order_by('-created')
> newstest1 = NewsData.objects.filter(created__lt= t -
> 300).order_by('-created')
> args = {'newstest': newstest, 'newstest1':newstest1,* 'newstest2':['Older
> than 5 min']*}
>
> Regards,
>
> Andréas
>
>
> Den ons 12 sep. 2018 kl 01:46 skrev Mikko Meronen <
> mikkovillemero...@gmail.com>:
>
>> Hi, I still have a small issue here and couldn't figure it out.
>>
>> I want to divide my items based on the time created. The division point
>> is 5 minutes and  I want that point to be seen in my webpage. However when
>> I made the division point, Django doesn't update it (the items that become
>> older than 5 mins do not move to the older group) until I restart the
>> server. Otherwise the new items will aggregate to the webpage as supposed.
>> Is there anyway in Django to make this work in views.py and templates?
>>
>> Otherwise I guess I should try to figure out if it is possible in SQL
>> side by creating more tables based on the creation time and updating the
>> tables there. Now all my items are in a single table.
>>
>> - Mikko
>>
>> t = time.time()
>>
>> def index(request):
>> newstest = NewsData.objects.filter(created__gt= t -
>> 300).order_by('-created')
>> newstest1 = NewsData.objects.filter(created__lt= t -
>> 300).order_by('-created')
>> args = {'newstest': newstest, 'newstest1':newstest1,* 'newstest2':['Older
>> than 5 min']*}
>> return render(request, "news/index.html", args)
>>
>>
>> 
>> 
>> 
>> 
>> {% for news in newstest %}
>>  {{ news.title }} 
>> {{ news.published }} {{ news.publisher }} {{ news.section }} {{
>> news.country }}
>> 
>> {% endfor %}
>> 
>> 
>> 
>> 
>> **
>> * *
>> * *
>> * *
>> * {% for c in newstest2 %}*
>> *  {{c}} *
>> * *
>> * {% endfor %}*
>> * *
>> * *
>> * *
>> * *
>>
>> 
>> 
>> 
>> 
>> {% for news1 in newstest1 %}
>>  {{ news1.title }} 
>> {{ news1.published }} {{ news1.publisher }} {{ news1.section }} {{
>> news1.country }}
>> 
>> {% endfor %}
>> 
>> 
>> 
>> 
>>
>> su 9. syysk. 2018 klo 17.21 Mikko Meronen (mikkovillemero...@gmail.com)
>> kirjoitti:
>>
>>> Thank you.
>>>
>>> -Mikko
>>>
>>> su 9. syysk. 2018 klo 16.49 Jason (jjohns98...@gmail.com) kirjoitti:
>>>
>>>> You've defined two views which pass in different querysets to be
>>>> rendered.
>>>>
>>>> so if you hit index, you get the first queryset rendered but not the
>>>> second because newstest1 is not rendered at all.  and vice versa.
>>>>
>>>> solution is to add newstest1 to index and pass both querysets as
>>>> context to the render.  eg
>>>>
>>>> return render(request,

Instagram embedding

2018-10-13 Thread Mikko Meronen
Hi,

I'm trying to embed Instagram to my development site by using a Instagram
embedding code, but when I add it to my html, I get the error below.

I would appreciate a lot if someone could help me to understand the error
and solve the problem.

Best regards,

- Mikko

UnicodeDecodeError at /news/

'utf-8' codec can't decode byte 0xe4 in position 7333: invalid continuation byte

Request Method: GET
Request URL: http://127.0.0.1:8000/news/
Django Version: 2.1
Exception Type: UnicodeDecodeError
Exception Value:

'utf-8' codec can't decode byte 0xe4 in position 7333: invalid continuation byte

Exception Location: C:\Users\Mikko\django-project\lib\codecs.py in decode,
line 321
Python Executable: C:\Users\Mikko\django-project\Scripts\python.exe
Python Version: 3.6.4
Python Path:

['C:\\Users\\Mikko\\django-project\\topi',
 'C:\\Users\\Mikko\\django-project\\Scripts\\python36.zip',
 'C:\\Users\\Mikko\\django-project\\DLLs',
 'C:\\Users\\Mikko\\django-project\\lib',
 'C:\\Users\\Mikko \\django-project\\Scripts',
 'c:\\python36-32\\Lib',
 'c:\\python36-32\\DLLs',
 'C:\\Users\\Mikko\\django-project',
 'C:\\Users\\Mikko\\django-project\\lib\\site-packages']

Server time: Sat, 13 Oct 2018 14:25:38 +
Unicode error hint

The string that could not be encoded/decoded was: *;"> N�yt� t*
Error during template rendering

In template C:\Users\Mikko\django-project\topi\news\templates\news\home.html,
error at line *1*
utf-8
1 {% extends 'news/base.html' %}

-- 
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/CAGD0jjKCjY0Gz%2BGqz5uAETvmR_Fw%3Df56EvNBaqeLt1gr4c6N3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Instagram embedding

2018-10-13 Thread Mikko Meronen
Hi,

It worked in production environment well, just not in development
environment.

- Mikko

la 13. lokak. 2018 klo 17.39 Mikko Meronen (mikkovillemero...@gmail.com)
kirjoitti:

> Hi,
>
> I'm trying to embed Instagram to my development site by using a Instagram
> embedding code, but when I add it to my html, I get the error below.
>
> I would appreciate a lot if someone could help me to understand the error
> and solve the problem.
>
> Best regards,
>
> - Mikko
>
> UnicodeDecodeError at /news/
>
> 'utf-8' codec can't decode byte 0xe4 in position 7333: invalid continuation 
> byte
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/news/
> Django Version: 2.1
> Exception Type: UnicodeDecodeError
> Exception Value:
>
> 'utf-8' codec can't decode byte 0xe4 in position 7333: invalid continuation 
> byte
>
> Exception Location: C:\Users\Mikko\django-project\lib\codecs.py in
> decode, line 321
> Python Executable: C:\Users\Mikko\django-project\Scripts\python.exe
> Python Version: 3.6.4
> Python Path:
>
> ['C:\\Users\\Mikko\\django-project\\topi',
>  'C:\\Users\\Mikko\\django-project\\Scripts\\python36.zip',
>  'C:\\Users\\Mikko\\django-project\\DLLs',
>  'C:\\Users\\Mikko\\django-project\\lib',
>  'C:\\Users\\Mikko \\django-project\\Scripts',
>  'c:\\python36-32\\Lib',
>  'c:\\python36-32\\DLLs',
>  'C:\\Users\\Mikko\\django-project',
>  'C:\\Users\\Mikko\\django-project\\lib\\site-packages']
>
> Server time: Sat, 13 Oct 2018 14:25:38 +
> Unicode error hint
>
> The string that could not be encoded/decoded was: *;"> N�yt� t*
> Error during template rendering
>
> In template
> C:\Users\Mikko\django-project\topi\news\templates\news\home.html, error
> at line *1*
> utf-8
> 1 {% extends 'news/base.html' %}
>

-- 
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/CAGD0jj%2BOn0d1mVx1Fq7B7-XEKQxPiBWT6QLts8sWrUkAFwUAng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Search function problem in production environment

2018-10-19 Thread Mikko Meronen
Hi again,

I am trying to deploy a search function to my website. It works well in the
development environment, but in the production side I get the error message
below (and my codes). I appreciate a lot if someone could help me again.
I'm using PythonAnywhere in production, if that matters.

Best regards,

Mikko

*Error:*

2018-10-19 13:13:13,629: Error running WSGI application
2018-10-19 13:13:13,630: IndexError: list index out of range
2018-10-19 13:13:13,630:   File
"/usr/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line
142, in __call__
2018-10-19 13:13:13,630: response = self.get_response(request)
2018-10-19 13:13:13,630:
2018-10-19 13:13:13,630:   File
"/usr/lib/python3.6/site-packages/django/core/handlers/base.py", line
78, in get_response
2018-10-19 13:13:13,631: response = self._middleware_chain(request)
2018-10-19 13:13:13,631:
2018-10-19 13:13:13,631:   File
"/usr/lib/python3.6/site-packages/django/core/handlers/exception.py",
line 36, in inner
2018-10-19 13:13:13,631: response = response_for_exception(request, exc)
2018-10-19 13:13:13,631:
2018-10-19 13:13:13,631:   File
"/usr/lib/python3.6/site-packages/django/core/handlers/exception.py",
line 90, in response_for_exception
2018-10-19 13:13:13,631: response =
handle_uncaught_exception(request, get_resolver(get_urlconf()),
sys.exc_info())
2018-10-19 13:13:13,631:
2018-10-19 13:13:13,631:   File
"/usr/lib/python3.6/site-packages/django/core/handlers/exception.py",
line 125, in handle_uncaught_exception
2018-10-19 13:13:13,632: return
debug.technical_500_response(request, *exc_info)
2018-10-19 13:13:13,632:
2018-10-19 13:13:13,632:   File
"/usr/lib/python3.6/site-packages/django/views/debug.py", line 94, in
technical_500_response
2018-10-19 13:13:13,632: html = reporter.get_traceback_html()
2018-10-19 13:13:13,632:
2018-10-19 13:13:13,632:   File
"/usr/lib/python3.6/site-packages/django/views/debug.py", line 333, in
get_traceback_html
2018-10-19 13:13:13,632: c = Context(self.get_traceback_data(),
use_l10n=False)
2018-10-19 13:13:13,632:
2018-10-19 13:13:13,632:   File
"/usr/lib/python3.6/site-packages/django/views/debug.py", line 264, in
get_traceback_data
2018-10-19 13:13:13,632: frames = self.get_traceback_frames()
2018-10-19 13:13:13,633:
2018-10-19 13:13:13,633:   File
"/usr/lib/python3.6/site-packages/django/views/debug.py", line 422, in
get_traceback_frames
2018-10-19 13:13:13,633: filename, lineno, 7, loader, module_name,
2018-10-19 13:13:13,633:
2018-10-19 13:13:13,633:   File
"/usr/lib/python3.6/site-packages/django/views/debug.py", line 383, in
_get_lines_from_file
2018-10-19 13:13:13,633: context_line = source[lineno]


*urls.py*

from django.urls import path
from . import views

app_name = 'news'

urlpatterns = [
path('', views.Home, name='home'),
path('all/', views.All_news, name='all'),
path('world/', views.World, name='world'),
path('sport/', views.Sport, name='sport'),
path('economy/', views.Business, name='economy'),
path('politics/', views.Politics, name='politics'),
path('scitech/', views.SciTech, name='scitech'),
path('search/', views.Search, name='search'),
]


*views.py:*

from django.db.models import Q

def Search(request):
query = request.GET.get('q')
results = news.objects.filter(Q(title__icontains=query) |
Q(publisher__icontains=query)).order_by('-created')
args = {'results': results}
return render(request, "news/search.html", args)


*base.html:*

news:search' %}" class="form-inline">


Search 



*search.html:*

{% for news in results %}
 {{ news.title }} 
 {{ news.publisher
}} | {{ news.subsection2 }} | {{ news.published }} 

{% 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/CAGD0jjJPcnpX3B_AQ9EiMzae-G_jecndaUqxdfK6f1wD1Oyk%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search function problem in production environment

2018-10-19 Thread Mikko Meronen
The code seems to work in production environment after all, just needed to
restart the site.

- Mikko

pe 19. lokak. 2018 klo 16.26 Mikko Meronen (mikkovillemero...@gmail.com)
kirjoitti:

> Hi again,
>
> I am trying to deploy a search function to my website. It works well in
> the development environment, but in the production side I get the error
> message below (and my codes). I appreciate a lot if someone could help me
> again. I'm using PythonAnywhere in production, if that matters.
>
> Best regards,
>
> Mikko
>
> *Error:*
>
> 2018-10-19 13:13:13,629: Error running WSGI application
> 2018-10-19 13:13:13,630: IndexError: list index out of range
> 2018-10-19 13:13:13,630:   File 
> "/usr/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 142, in 
> __call__
> 2018-10-19 13:13:13,630: response = self.get_response(request)
> 2018-10-19 13:13:13,630:
> 2018-10-19 13:13:13,630:   File 
> "/usr/lib/python3.6/site-packages/django/core/handlers/base.py", line 78, in 
> get_response
> 2018-10-19 13:13:13,631: response = self._middleware_chain(request)
> 2018-10-19 13:13:13,631:
> 2018-10-19 13:13:13,631:   File 
> "/usr/lib/python3.6/site-packages/django/core/handlers/exception.py", line 
> 36, in inner
> 2018-10-19 13:13:13,631: response = response_for_exception(request, exc)
> 2018-10-19 13:13:13,631:
> 2018-10-19 13:13:13,631:   File 
> "/usr/lib/python3.6/site-packages/django/core/handlers/exception.py", line 
> 90, in response_for_exception
> 2018-10-19 13:13:13,631: response = handle_uncaught_exception(request, 
> get_resolver(get_urlconf()), sys.exc_info())
> 2018-10-19 13:13:13,631:
> 2018-10-19 13:13:13,631:   File 
> "/usr/lib/python3.6/site-packages/django/core/handlers/exception.py", line 
> 125, in handle_uncaught_exception
> 2018-10-19 13:13:13,632: return debug.technical_500_response(request, 
> *exc_info)
> 2018-10-19 13:13:13,632:
> 2018-10-19 13:13:13,632:   File 
> "/usr/lib/python3.6/site-packages/django/views/debug.py", line 94, in 
> technical_500_response
> 2018-10-19 13:13:13,632: html = reporter.get_traceback_html()
> 2018-10-19 13:13:13,632:
> 2018-10-19 13:13:13,632:   File 
> "/usr/lib/python3.6/site-packages/django/views/debug.py", line 333, in 
> get_traceback_html
> 2018-10-19 13:13:13,632: c = Context(self.get_traceback_data(), 
> use_l10n=False)
> 2018-10-19 13:13:13,632:
> 2018-10-19 13:13:13,632:   File 
> "/usr/lib/python3.6/site-packages/django/views/debug.py", line 264, in 
> get_traceback_data
> 2018-10-19 13:13:13,632: frames = self.get_traceback_frames()
> 2018-10-19 13:13:13,633:
> 2018-10-19 13:13:13,633:   File 
> "/usr/lib/python3.6/site-packages/django/views/debug.py", line 422, in 
> get_traceback_frames
> 2018-10-19 13:13:13,633: filename, lineno, 7, loader, module_name,
> 2018-10-19 13:13:13,633:
> 2018-10-19 13:13:13,633:   File 
> "/usr/lib/python3.6/site-packages/django/views/debug.py", line 383, in 
> _get_lines_from_file
> 2018-10-19 13:13:13,633: context_line = source[lineno]
>
>
> *urls.py*
>
> from django.urls import path
> from . import views
>
> app_name = 'news'
>
> urlpatterns = [
> path('', views.Home, name='home'),
> path('all/', views.All_news, name='all'),
> path('world/', views.World, name='world'),
> path('sport/', views.Sport, name='sport'),
> path('economy/', views.Business, name='economy'),
> path('politics/', views.Politics, name='politics'),
> path('scitech/', views.SciTech, name='scitech'),
> path('search/', views.Search, name='search'),
> ]
>
>
> *views.py:*
>
> from django.db.models import Q
>
> def Search(request):
> query = request.GET.get('q')
> results = news.objects.filter(Q(title__icontains=query) | 
> Q(publisher__icontains=query)).order_by('-created')
> args = {'results': results}
> return render(request, "news/search.html", args)
>
>
> *base.html:*
>
> news:search' %}" class="form-inline">
>  value="{{request.GET.q}}" placeholder="search" aria-label="Search">
> 
> Search 
> 
>
>
> *search.html:*
>
> {% for news in results %}
>  {{ news.title }} 
>  {{ news.publisher }} | 
> {{ news.subsection2 }} | {{ news.published }} 
> 
> {% 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/CAGD0jjL5mGJvtN%2B160%2BSa7ODoZ0qG%3DTa8oEvOUngmKCL5F-_ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problem: Ajax post method to django views

2019-11-08 Thread Mikko Meronen
Hi,

I have a problem to pass a json value to Django views and use the value to 
retrieve data from my database. Anyone could help me?

I get the ajax error message and the following error in chrome console:
jquery.js:8475 POST http://www.topithenewsdoggy.com/history/ 403 (Forbidden)

*views.py*

def History(request):

md = request.POST.get('jsonData')
historia1 = history.objects.filter(monthday__exact=md)[:1]
args = {'historia1':historia1}
return render(request, "news/history.html", args)


*history.html:*

http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js";>


var x = new Date();
var m = x.getMonth() + 1;
var d = x.getDate();
var monthdate = m + '-' + d;

var jsonData = JSON.stringify(monthdate);

$.ajax({
type: "POST",
url: '/history/',
data: { jsonData },
dataType : "json",
success: function () { alert("Success"); },
error: function () alert("Error"); }
});



// CSFR

function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = 
decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
var csrftoken = getCookie('csrftoken');

function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = 
decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

var csrftoken = getCookie('csrftoken');

function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});


-- 
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/2e129166-4262-4c39-b4d8-517dd9249f1a%40googlegroups.com.