Re: How to over ride the get context data method in view

2020-05-13 Thread Andréas Kühne
Hi,

We can't solve all of your problems for you :) But that being said - in the
get_context_data you don't have a parameter for the request, however in all
CBV you get the request as a variable on the CBV itself - so change:

post.is_liked = post.likes.filter(user=request.user).exists()

To:


post.is_liked = post.likes.filter(user=self.request.user).exists()

Regards,

Andréas


Den ons 13 maj 2020 kl 22:10 skrev Ahmed Khairy :

> still showing the same error
>
> On Wednesday, May 13, 2020 at 2:34:03 PM UTC-4, Yamen Gamal Eldin wrote:
>>
>> I haven't seen any definition for user within ur function, so
>> Change this
>> post.is_liked = post.likes.filter(user=user).exists()
>>
>> To this
>>
>> post.is_liked = post.likes.filter(user=request.user).exists()
>>
>>
>> Le mer. 13 mai 2020 à 19:22, Ahmed Khairy  a
>> écrit :
>>
>>> Hi There,
>>>
>>> I have rewritten the get_context_data method to be like this but I am
>>> getting name 'user' is not defined:
>>>
>>>
>>> class PostListView(ListView):
>>> model = Post
>>> template_name = "score.html"
>>> ordering = ['-date_posted']
>>> context_object_name = 'posts'
>>> paginate_by = 5
>>>
>>> def get_context_data(self, **kwargs):
>>> context_data = super(PostListView, self).get_context_data(**
>>> kwargs)
>>> for post in context_data['posts']:
>>> post.is_liked = post.likes.filter(user=user).exists()
>>> <- name 'user' is not defined
>>> return context
>>>
>>> I am also using this template just for testing till fix the issue
>>>
>>> Thank you Andreas with me
>>>
>>>
>>> On Wednesday, May 13, 2020 at 12:31:15 PM UTC-4, Andréas Kühne wrote:

 Hi again,

 Bare with me - this is just written in this email - so:

 1. Your listview is paginated by 5, so it will only show 5 posts -
 that's good for this exercise and how I would solve it.
 2. Rewrite your get_context_data method to iterate over the posts:
 def get_context_data(self, **kwargs):
 context_data = super(PostListView,
 self).get_context_data(**kwargs)
 for post in context_data['posts']:
 post.is_liked = post.likes.filter(user=user).exists()
 return context

 So now your page should show. In the page template:

 % extends "base.html"%} {% block content %} {% for post in posts %}
 {{post.title}}
 
   {% csrf_token 
 %} {% if is_like %}   >>> type="submit">Unlike

   {% else %}
   Like
   {% endif %}{% endfor %} {% endblock content %}

 Something like this should give you the functionality you want -
 however it's still a bit cumbersome.

 Regards,

 Andréas


 Den ons 13 maj 2020 kl 15:24 skrev Ahmed Khairy >>> >:

> Hi Andréas Kühne,
>
> Regarding the first error
>
> I have a list of posts in the listView and want to add the like button
> to each post so how should I fix it?
>
> Thank you
>
> On Wednesday, May 13, 2020 at 6:08:31 AM UTC-4, Andréas Kühne wrote:
>>
>> Hi,
>>
>> There are a couple of errors in your code:
>>
>> 1. You are using a ListView and then trying to get an individual
>> post? That is really strange
>> 2. In your get_context_data method - you first get the context data,
>> update it and then you set it to a new dict, so everything is reset in 
>> the
>> dict.
>> 3. you are trying to get the absolut url for your post, but aren't
>> showing any post detail view.
>>
>> Regards,
>>
>> Andréas
>>
>>
>> Den ons 13 maj 2020 kl 06:46 skrev Ahmed Khairy <
>> ahmed.he...@gmail.com>:
>>
>>> I am currently trying to create a like button for my posts in Django
>>>
>>> I have reached to the part where I can add a like but I am facing
>>> difficulty writing the code related to the view which linking the
>>> PostListView if there is user who liked it or not. I am getting an 
>>> error:
>>> page Error 404 although everything is correct
>>>
>>>
>>> this the views:
>>>
>>>
>>> class PostListView(ListView):
>>> model = Post
>>> template_name = "score.html"
>>> ordering = ['-date_posted']
>>> context_object_name = 'posts'
>>> queryset = Post.objects.filter(admin_approved=True)
>>> paginate_by = 5
>>>
>>> def get_context_data(self, **kwargs):
>>> post = get_object_or_404(Post, id=self.request.POST.get(
>>> 'post_id'))
>>> context = super(PostListView, self).get_context_data(**
>>> kwargs)
>>> context['posts'][0].likes.filter(id=self.request.user.id).
>>> exists()
>>> is_liked = False
>>> if post.likes.filter(id=self.request.user.id).exists():
>>> is_liked = True
>>> context = {'post': post,
>>>'is_like': is_like

Inserting data from a text file is not working for Postgres database

2020-05-13 Thread Ram
 Hi,

We are trying to insert the data from a text file '*some_category_list.txt*''
into a table in Postgres database using the highlighted query in our
functions.py

file = open(str(a)+'_category_list.txt', 'r')
> file_content = file.read()
> print(file_content)
> file.close()
> from django.db import connection
> cursor = connection.cursor()
> *query = "COPY pages_rim_ls_categories FROM '{0}_category_list.txt' WITH
> DELIMITER AS '|'".format(str(a)) *
> cursor.execute(query)
>
>
and we are getting this error

django.db.utils.OperationalError: could not open file
> "some_category_list.txt" for reading: No such file or directory
>


> HINT: COPY FROM instructs the PostgreSQL server process to read a file.
> You may want a client-side facility such as psql's \copy.
>

Note: We used below query in the past using MySQL and it worked fine with
that.

query = "LOAD DATA LOCAL INFILE '*some_category_list.txt'* INTO TABLE
> pages_rim_ls_categories FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n' "
>

We are wondering what we are missing. Could someone help here to verify
this?

Best regards
~Ram

-- 
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/CA%2BOi5F2P8Oy-gOUWC54imqcNvdmHw3LuC%3DuKkR5Xzq_w3HXjjA%40mail.gmail.com.


Re: Deploying Django Project on heroku

2020-05-13 Thread Shyam Acharjya
dude the error is staring at you. have you read the logs? just update the
whitenoise library. django.utils.six is deprecated. if you want to use six
you have to import it independently.

On Thu, May 14, 2020 at 8:28 AM Akshat Zala  wrote:

> If possible, please downgrade the django version to django2.2 LTS and try
> again...
>
> --
> 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/536aaeb3-f6a7-4dcf-b856-927a79b3a08f%40googlegroups.com
> .
>

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


Re: Deploying Django Project on heroku

2020-05-13 Thread Akshat Zala
If possible, please downgrade the django version to django2.2 LTS and try 
again...

-- 
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/536aaeb3-f6a7-4dcf-b856-927a79b3a08f%40googlegroups.com.


Re: Deploying Django Project on heroku

2020-05-13 Thread Akshat Zala
If possible, please downgrade DJ version to 2.2 LTS and try again to execute 
the code.

-- 
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/892a5df3-2fc0-4a0c-98b5-9f8d1bb6990a%40googlegroups.com.


how to save multiple checkbox values and checked status(true or false) in the django....

2020-05-13 Thread frontend developer
Hello,  i am beginner to django, i am sending values and checked status 
from the front end using checkboxesnow i do not no how to write frame 
work in the django, can i get any help on these

-- 
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/5d8b65e8-92a8-48c3-9a91-6a0b24c4a4fa%40googlegroups.com.


How to write a Get_Context_method

2020-05-13 Thread Ahmed Khairy
Hi,

I have the following context and I am trying to write it correctly in a 
function 

This is context data :

def post_view(request):
qs= Post.objects.all()
user= request.user

context= {
'qs':qs,
'user':user,
} 

I am trying to define it in a class PostListView(ListView):

I need help writing it correctly 

-- 
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/e81a0fc9-f0ab-4f3b-b61d-827a67db0466%40googlegroups.com.


Re: How to over ride the get context data method in view

2020-05-13 Thread Ahmed Khairy
still showing the same error

On Wednesday, May 13, 2020 at 2:34:03 PM UTC-4, Yamen Gamal Eldin wrote:
>
> I haven't seen any definition for user within ur function, so 
> Change this 
> post.is_liked = post.likes.filter(user=user).exists()
>
> To this
>
> post.is_liked = post.likes.filter(user=request.user).exists()
>
>
> Le mer. 13 mai 2020 à 19:22, Ahmed Khairy  > a écrit :
>
>> Hi There, 
>>
>> I have rewritten the get_context_data method to be like this but I am 
>> getting name 'user' is not defined:
>>
>>
>> class PostListView(ListView):
>> model = Post
>> template_name = "score.html"
>> ordering = ['-date_posted']
>> context_object_name = 'posts'
>> paginate_by = 5
>>
>> def get_context_data(self, **kwargs):
>> context_data = super(PostListView, self).get_context_data(**
>> kwargs)
>> for post in context_data['posts']:
>> post.is_liked = post.likes.filter(user=user).exists() <- 
>> name 'user' is not defined
>> return context
>>
>> I am also using this template just for testing till fix the issue 
>>
>> Thank you Andreas with me
>>
>>
>> On Wednesday, May 13, 2020 at 12:31:15 PM UTC-4, Andréas Kühne wrote:
>>>
>>> Hi again,
>>>
>>> Bare with me - this is just written in this email - so:
>>>
>>> 1. Your listview is paginated by 5, so it will only show 5 posts - 
>>> that's good for this exercise and how I would solve it.
>>> 2. Rewrite your get_context_data method to iterate over the posts:
>>> def get_context_data(self, **kwargs):
>>> context_data = super(PostListView, 
>>> self).get_context_data(**kwargs)
>>> for post in context_data['posts']:
>>> post.is_liked = post.likes.filter(user=user).exists()
>>> return context
>>>
>>> So now your page should show. In the page template:
>>>
>>> % extends "base.html"%} {% block content %} {% for post in posts %}
>>> {{post.title}}
>>> 
>>>   {% csrf_token 
>>> %} {% if is_like %}   >> type="submit">Unlike
>>>
>>>   {% else %}
>>>   Like
>>>   {% endif %}{% endfor %} {% endblock content %} 
>>>
>>> Something like this should give you the functionality you want - however 
>>> it's still a bit cumbersome.
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>>
>>> Den ons 13 maj 2020 kl 15:24 skrev Ahmed Khairy :
>>>
 Hi Andréas Kühne,

 Regarding the first error

 I have a list of posts in the listView and want to add the like button 
 to each post so how should I fix it? 

 Thank you 

 On Wednesday, May 13, 2020 at 6:08:31 AM UTC-4, Andréas Kühne wrote:
>
> Hi,
>
> There are a couple of errors in your code:
>
> 1. You are using a ListView and then trying to get an individual post? 
> That is really strange
> 2. In your get_context_data method - you first get the context data, 
> update it and then you set it to a new dict, so everything is reset in 
> the 
> dict.
> 3. you are trying to get the absolut url for your post, but aren't 
> showing any post detail view.
>
> Regards,
>
> Andréas
>
>
> Den ons 13 maj 2020 kl 06:46 skrev Ahmed Khairy  >:
>
>> I am currently trying to create a like button for my posts in Django
>>
>> I have reached to the part where I can add a like but I am facing 
>> difficulty writing the code related to the view which linking the 
>> PostListView if there is user who liked it or not. I am getting an 
>> error: 
>> page Error 404 although everything is correct
>>
>>
>> this the views: 
>>
>>
>> class PostListView(ListView):
>> model = Post
>> template_name = "score.html"
>> ordering = ['-date_posted']
>> context_object_name = 'posts'
>> queryset = Post.objects.filter(admin_approved=True)
>> paginate_by = 5
>>
>> def get_context_data(self, **kwargs):
>> post = get_object_or_404(Post, id=self.request.POST.get(
>> 'post_id'))
>> context = super(PostListView, self).get_context_data(**
>> kwargs)
>> context['posts'][0].likes.filter(id=self.request.user.id).
>> exists()
>> is_liked = False
>> if post.likes.filter(id=self.request.user.id).exists():
>> is_liked = True
>> context = {'post': post,
>>'is_like': is_liked,
>>}
>> return context
>>
>>
>>
>> def like_post(request):
>> post = get_object_or_404(Post, id=request.POST.get('post_id'))
>> is_liked = False
>> if post.likes.filter(id=request.user.id).exists():
>> posts.likes.remove(request.user)
>> is_liked = False
>>
>> else:
>> post.likes.add(request.user)
>> is_liked = True
>>
>> return HttpResponseRedirect(post.get_absolute_url())
>>
>>
>> This is the model 
>>
>>
>> cl

Gunicorn-wsgi-nginx-postgresql-django linode hosting

2020-05-13 Thread Tobi DEGNON
Hi I need help, I'm hosting a django app on linode, the app is running on 
Ubuntu 18.04 LTS with gunicorn, nginx a postgresql database, and I'm using 
let's encrypt for SSL certificate, the issue is when I fill a form (login 
or signup) I get a timeout error but I don't have that issue on the admin 
site, when I try login to the admin it works just fine, and I don't have 
the timeout error on my local machine on the app, this is like the fourth 
time I'm setting up the whole thing with a different Ubuntu version each 
time, and I'm having the exact same issue, I made some research and then 
update timeout for nginx and gunicorn to 300, but it doesn't work, this is 
the first time I'm hosting a django app on a Linux server and I'm having 
the worst time of my life, this is a full traceback of the error 
https://gist.github.com/Tobi-De/38a3badf79bdf9fb0fe45cb0322d6293 , dont't 
let that EmailAddress.DoesNotExist exception full you, it does exist, I 
create the account with the createsuperuser command.

-- 
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/e2a4a4ae-f949-464a-adbb-b0b6f7fa2f65%40googlegroups.com.


Re: Deploying Django Project on heroku

2020-05-13 Thread Sunday Iyanu Ajayi
Django 3.0.5
*AJAYI Sunday *
(+234) 806 771 5394
*sunnexaj...@gmail.com *



On Wed, May 13, 2020 at 4:17 PM Akshat Zala  wrote:

> Which version of django are you using?
>
> On Saturday, 9 May 2020 19:21:53 UTC+5:30, Sunday Iyanu Ajayi wrote:
>>
>> I have but I still get error
>>
>> [image: image.png]
>> *AJAYI Sunday *
>> (+234) 806 771 5394
>> *sunne...@gmail.com*
>>
>>
>>
>> On Sat, May 9, 2020 at 1:50 PM ola neat  wrote:
>>
>>> Halo, i feel if u follow the step in this article
>>> https://www.codementor.io/@jamesezechukwu/how-to-deploy-django-app-on-heroku-dtsee04d4
>>> u should b good
>>>
>>> On Sat, May 9, 2020, 01:15 Sunday Iyanu Ajayi 
>>> wrote:
>>>
 Hi Motaz,
 Thank you so much.
 Is today cool?
 What time (in GMT+1) will be cool for you?

 *AJAYI Sunday *
 (+234) 806 771 5394
 *sunne...@gmail.com*



 On Sun, May 3, 2020 at 11:05 PM Motaz Hejaze  wrote:

> Let us have a zoom meeting to fix it
>
> On Sun, 3 May 2020, 11:45 pm Sunday Iyanu Ajayi, 
> wrote:
>
>> I have but it keeps telling  that it is misconfigured
>> *AJAYI Sunday *
>> (+234) 806 771 5394
>> *sunne...@gmail.com*
>>
>>
>>
>> On Sat, Apr 25, 2020 at 3:17 PM sagar ninave 
>> wrote:
>>
>>> Do you installed whitenoise package
>>> If not then run this command
>>> Pip insatll whitenoise
>>>
>>> On Sat, 25 Apr 2020 at 7:43 PM, Sunday Iyanu Ajayi <
>>> sunne...@gmail.com> wrote:
>>>
 I have spent over 2weeks on deploying a django project to heroku
 but I keep getting error messages such as :

 My WhiteNoise is not configured  and I have followed all the
 tutorials recommended  and yet same thing.

 Please who has a guide I can follow that is very updated.
 Thank you.
 *AJAYI Sunday *
 (+234) 806 771 5394
 *sunne...@gmail.com*

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

>>> --
>>>
>>> 
>>> sagar ninave
>>> about.me/sagarninave
>>> 
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>>> send an email to django...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAA6pdZ9fsGj3y%3DNVVQ_oCX9hY5DbLHtPVLM-nPhWYxpE4Qsi7w%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to django...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAKYSAw2hYQGRYYZRB%3D7ZNJJJ-1OY2ykShsPam9xiRc-8M4BQJg%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHV4E-dLr30ycFTo9tccTmKW74rvDA%3D0Oks8NqAVez0Tiyzocg%40mail.gmail.com
> 
> .
>
 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django...@googlegroups.com.
 To view this discussion on the web visit
 https

Re: How to over ride the get context data method in view

2020-05-13 Thread Yamen Gamal Eldin
I haven't seen any definition for user within ur function, so
Change this
post.is_liked = post.likes.filter(user=user).exists()

To this

post.is_liked = post.likes.filter(user=request.user).exists()


Le mer. 13 mai 2020 à 19:22, Ahmed Khairy  a
écrit :

> Hi There,
>
> I have rewritten the get_context_data method to be like this but I am
> getting name 'user' is not defined:
>
>
> class PostListView(ListView):
> model = Post
> template_name = "score.html"
> ordering = ['-date_posted']
> context_object_name = 'posts'
> paginate_by = 5
>
> def get_context_data(self, **kwargs):
> context_data = super(PostListView, self).get_context_data(**
> kwargs)
> for post in context_data['posts']:
> post.is_liked = post.likes.filter(user=user).exists() <-
> name 'user' is not defined
> return context
>
> I am also using this template just for testing till fix the issue
>
> Thank you Andreas with me
>
>
> On Wednesday, May 13, 2020 at 12:31:15 PM UTC-4, Andréas Kühne wrote:
>>
>> Hi again,
>>
>> Bare with me - this is just written in this email - so:
>>
>> 1. Your listview is paginated by 5, so it will only show 5 posts - that's
>> good for this exercise and how I would solve it.
>> 2. Rewrite your get_context_data method to iterate over the posts:
>> def get_context_data(self, **kwargs):
>> context_data = super(PostListView,
>> self).get_context_data(**kwargs)
>> for post in context_data['posts']:
>> post.is_liked = post.likes.filter(user=user).exists()
>> return context
>>
>> So now your page should show. In the page template:
>>
>> % extends "base.html"%} {% block content %} {% for post in posts %}
>> {{post.title}}
>> 
>>   {% csrf_token %} 
>> {% if is_like %}   > type="submit">Unlike
>>
>>   {% else %}
>>   Like
>>   {% endif %}{% endfor %} {% endblock content %}
>>
>> Something like this should give you the functionality you want - however
>> it's still a bit cumbersome.
>>
>> Regards,
>>
>> Andréas
>>
>>
>> Den ons 13 maj 2020 kl 15:24 skrev Ahmed Khairy :
>>
>>> Hi Andréas Kühne,
>>>
>>> Regarding the first error
>>>
>>> I have a list of posts in the listView and want to add the like button
>>> to each post so how should I fix it?
>>>
>>> Thank you
>>>
>>> On Wednesday, May 13, 2020 at 6:08:31 AM UTC-4, Andréas Kühne wrote:

 Hi,

 There are a couple of errors in your code:

 1. You are using a ListView and then trying to get an individual post?
 That is really strange
 2. In your get_context_data method - you first get the context data,
 update it and then you set it to a new dict, so everything is reset in the
 dict.
 3. you are trying to get the absolut url for your post, but aren't
 showing any post detail view.

 Regards,

 Andréas


 Den ons 13 maj 2020 kl 06:46 skrev Ahmed Khairy >>> >:

> I am currently trying to create a like button for my posts in Django
>
> I have reached to the part where I can add a like but I am facing
> difficulty writing the code related to the view which linking the
> PostListView if there is user who liked it or not. I am getting an error:
> page Error 404 although everything is correct
>
>
> this the views:
>
>
> class PostListView(ListView):
> model = Post
> template_name = "score.html"
> ordering = ['-date_posted']
> context_object_name = 'posts'
> queryset = Post.objects.filter(admin_approved=True)
> paginate_by = 5
>
> def get_context_data(self, **kwargs):
> post = get_object_or_404(Post, id=self.request.POST.get(
> 'post_id'))
> context = super(PostListView, self).get_context_data(**kwargs)
> context['posts'][0].likes.filter(id=self.request.user.id).
> exists()
> is_liked = False
> if post.likes.filter(id=self.request.user.id).exists():
> is_liked = True
> context = {'post': post,
>'is_like': is_liked,
>}
> return context
>
>
>
> def like_post(request):
> post = get_object_or_404(Post, id=request.POST.get('post_id'))
> is_liked = False
> if post.likes.filter(id=request.user.id).exists():
> posts.likes.remove(request.user)
> is_liked = False
>
> else:
> post.likes.add(request.user)
> is_liked = True
>
> return HttpResponseRedirect(post.get_absolute_url())
>
>
> This is the model
>
>
> class Post(models.Model):
> designer = models.ForeignKey(User, on_delete=models.CASCADE)
> title = models.CharField(max_length=100)
> date_posted = models.DateTimeField(default=timezone.now)
> likes = models.ManyToManyField(User, blank=True, related_name='likes')
>
> def __st

password reset pages are not showing customizing html file

2020-05-13 Thread Ali Ahammad
hello everyone

i am trying to make a blog where i am trying to customize password reset 
forms. 
here is my bloggapp/urls.py:
from django.contrib import admin
from django.urls import path, include 
from django.views.generic.base import TemplateView 
from django.contrib.auth import views as auth_views

urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('accounts.urls')), 
#path('users/', include('django.contrib.auth.urls')), 
path('accounts/login/', auth_views.LoginView.as_view(template_name=
'registration/login.html'), name='login'),
path('accounts/logout/', auth_views.LogoutView.as_view(template_name=
'logout.html'), name='logout'),
path('', include('blog.urls')),
path('password-reset/', 
 auth_views.PasswordResetView.as_view
 (template_name='registration/password_reset.html'), 
 name='password_reset'),
path('password-reset/done/', 
 auth_views.PasswordResetDoneView.as_view
 (template_name='registration/password_reset_done.html'), 
 name='password_reset_done'),
path('password-reset-confirm///',
 auth_views.PasswordResetConfirmView.as_view(
 template_name='registration/password_reset_confirm.html'
 ),
 name='password_reset_confirm'),
 path('password-reset-complete/',
 auth_views.PasswordResetCompleteView.as_view(
 template_name='registration/password_reset_complete.html'
 ),
 name='password_reset_complete'),

]

http://localhost:8000/password-reset/ this page is showing the html form i 
have wrote in registration/password_reset.html directory which is under 
accounts app. in the accounts app there is templates folder and in this 
folder i have kept base.html. in the same folder i have created 
registration folder where i kept login.html and password_reset.html.

i have set up my email smtp in sendgrid and it is working. besides 
registration/login.html,templates/signup.html files are working.
i am including my base.html file also:









https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/\
bootstrap.min.css" integrity=
"sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81i\
uXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
{% block title %}Newspaper App{% endblock title %}




Newspaper



{% if user.is_authenticated %}



{{ user.username }}


Change password


Log Out



{% else %}


Log In

Sign up

{% endif %}



{% block content %}
{% endblock content %}



https://code.jquery.com/jquery-3.3.1.slim.min.js"; integrity
="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4\
YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous">
https://cdnjs.cloudflare.com/ajax/libs/popper.js/\
1.14.3/
umd/popper.min.js" integrity=
"sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbB\
JiSnjAK/
l8WvCWPIPm49" crossorigin="anonymous">
https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/\
js/bootstrap.min.js" integrity=
"sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ\
6OW/JmZQ5stwEULTy" crossorigin="anonymous">




and templates/home.html also:
{% extends 'base.html' %}
{% block title %}Home{% endblock title %}
{% block content %}
{% if user.is_authenticated %}
Hi {{ user.username }}!
Log Out
{% else %}
You are not logged in
Log In |
Sign Up
{% endif %}
{% endblock content %}


but the below mentioned html files are not showing in the browser but they 
are coming as django administration view.




{% extends 'base.html' %}
{% block title %}Password reset complete{% endblock title %}
{% block content %}
Password reset complete
Your new password has been set. You can log in now on the
log in page.
{% endblock content %}


{% extends "base.html" %}
 {% load crispy_forms_tags %} 
{% block content %}


{% csrf_token %}

Reset Password
{{ form|crispy }}



Reset Password



{% endblock content %}


{% extends "base.html" %}
{% block content %}

Your password has been set.

Sign In Here
{% endblock content %}


i don't what i have made wrong. will you please point me in the right 
direction? i really need 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 view this discussion on the web visit 
https://gr

Re: How to over ride the get context data method in view

2020-05-13 Thread Ahmed Khairy
Hi There, 

I have rewritten the get_context_data method to be like this but I am 
getting name 'user' is not defined:


class PostListView(ListView):
model = Post
template_name = "score.html"
ordering = ['-date_posted']
context_object_name = 'posts'
paginate_by = 5

def get_context_data(self, **kwargs):
context_data = super(PostListView, self).get_context_data(**kwargs)
for post in context_data['posts']:
post.is_liked = post.likes.filter(user=user).exists() <- 
name 'user' is not defined
return context

I am also using this template just for testing till fix the issue 

Thank you Andreas with me


On Wednesday, May 13, 2020 at 12:31:15 PM UTC-4, Andréas Kühne wrote:
>
> Hi again,
>
> Bare with me - this is just written in this email - so:
>
> 1. Your listview is paginated by 5, so it will only show 5 posts - that's 
> good for this exercise and how I would solve it.
> 2. Rewrite your get_context_data method to iterate over the posts:
> def get_context_data(self, **kwargs):
> context_data = super(PostListView, self).get_context_data(**kwargs)
> for post in context_data['posts']:
> post.is_liked = post.likes.filter(user=user).exists()
> return context
>
> So now your page should show. In the page template:
>
> % extends "base.html"%} {% block content %} {% for post in posts %}
> {{post.title}}
> 
>   {% csrf_token %} 
> {% if is_like %}type="submit">Unlike
>
>   {% else %}
>   Like
>   {% endif %}{% endfor %} {% endblock content %} 
>
> Something like this should give you the functionality you want - however 
> it's still a bit cumbersome.
>
> Regards,
>
> Andréas
>
>
> Den ons 13 maj 2020 kl 15:24 skrev Ahmed Khairy  >:
>
>> Hi Andréas Kühne,
>>
>> Regarding the first error
>>
>> I have a list of posts in the listView and want to add the like button to 
>> each post so how should I fix it? 
>>
>> Thank you 
>>
>> On Wednesday, May 13, 2020 at 6:08:31 AM UTC-4, Andréas Kühne wrote:
>>>
>>> Hi,
>>>
>>> There are a couple of errors in your code:
>>>
>>> 1. You are using a ListView and then trying to get an individual post? 
>>> That is really strange
>>> 2. In your get_context_data method - you first get the context data, 
>>> update it and then you set it to a new dict, so everything is reset in the 
>>> dict.
>>> 3. you are trying to get the absolut url for your post, but aren't 
>>> showing any post detail view.
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>>
>>> Den ons 13 maj 2020 kl 06:46 skrev Ahmed Khairy :
>>>
 I am currently trying to create a like button for my posts in Django

 I have reached to the part where I can add a like but I am facing 
 difficulty writing the code related to the view which linking the 
 PostListView if there is user who liked it or not. I am getting an error: 
 page Error 404 although everything is correct


 this the views: 


 class PostListView(ListView):
 model = Post
 template_name = "score.html"
 ordering = ['-date_posted']
 context_object_name = 'posts'
 queryset = Post.objects.filter(admin_approved=True)
 paginate_by = 5

 def get_context_data(self, **kwargs):
 post = get_object_or_404(Post, id=self.request.POST.get(
 'post_id'))
 context = super(PostListView, self).get_context_data(**kwargs)
 context['posts'][0].likes.filter(id=self.request.user.id).
 exists()
 is_liked = False
 if post.likes.filter(id=self.request.user.id).exists():
 is_liked = True
 context = {'post': post,
'is_like': is_liked,
}
 return context



 def like_post(request):
 post = get_object_or_404(Post, id=request.POST.get('post_id'))
 is_liked = False
 if post.likes.filter(id=request.user.id).exists():
 posts.likes.remove(request.user)
 is_liked = False

 else:
 post.likes.add(request.user)
 is_liked = True

 return HttpResponseRedirect(post.get_absolute_url())


 This is the model 


 class Post(models.Model):
 designer = models.ForeignKey(User, on_delete=models.CASCADE)
 title = models.CharField(max_length=100)
 date_posted = models.DateTimeField(default=timezone.now)
 likes = models.ManyToManyField(User, blank=True, related_name='likes')

 def __str__(self):
 return self.title

 Here is the

 path('like/', like_post, name='like_post'),

 here is the template: 

 {% extends "base.html"%} {% block content %} {% for post in posts %}
 {{post.title}}
 
   {% csrf_token %} {% if is_like %}
   
   Unlike
   {% else %}
   Like
   {% endif %}Likes 

 {% endfor %} {% endblock content

Re: How to over ride the get context data method in view

2020-05-13 Thread Andréas Kühne
Hi again,

Bare with me - this is just written in this email - so:

1. Your listview is paginated by 5, so it will only show 5 posts - that's
good for this exercise and how I would solve it.
2. Rewrite your get_context_data method to iterate over the posts:
def get_context_data(self, **kwargs):
context_data = super(PostListView, self).get_context_data(**kwargs)
for post in context_data['posts']:
post.is_liked = post.likes.filter(user=user).exists()
return context

So now your page should show. In the page template:

% extends "base.html"%} {% block content %} {% for post in posts %}
{{post.title}}

  {%
csrf_token %} {% if is_like %}   Unlike

  {% else %}
  Like
  {% endif %}{% endfor %} {% endblock content %}

Something like this should give you the functionality you want - however
it's still a bit cumbersome.

Regards,

Andréas


Den ons 13 maj 2020 kl 15:24 skrev Ahmed Khairy :

> Hi Andréas Kühne,
>
> Regarding the first error
>
> I have a list of posts in the listView and want to add the like button to
> each post so how should I fix it?
>
> Thank you
>
> On Wednesday, May 13, 2020 at 6:08:31 AM UTC-4, Andréas Kühne wrote:
>>
>> Hi,
>>
>> There are a couple of errors in your code:
>>
>> 1. You are using a ListView and then trying to get an individual post?
>> That is really strange
>> 2. In your get_context_data method - you first get the context data,
>> update it and then you set it to a new dict, so everything is reset in the
>> dict.
>> 3. you are trying to get the absolut url for your post, but aren't
>> showing any post detail view.
>>
>> Regards,
>>
>> Andréas
>>
>>
>> Den ons 13 maj 2020 kl 06:46 skrev Ahmed Khairy :
>>
>>> I am currently trying to create a like button for my posts in Django
>>>
>>> I have reached to the part where I can add a like but I am facing
>>> difficulty writing the code related to the view which linking the
>>> PostListView if there is user who liked it or not. I am getting an error:
>>> page Error 404 although everything is correct
>>>
>>>
>>> this the views:
>>>
>>>
>>> class PostListView(ListView):
>>> model = Post
>>> template_name = "score.html"
>>> ordering = ['-date_posted']
>>> context_object_name = 'posts'
>>> queryset = Post.objects.filter(admin_approved=True)
>>> paginate_by = 5
>>>
>>> def get_context_data(self, **kwargs):
>>> post = get_object_or_404(Post, id=self.request.POST.get(
>>> 'post_id'))
>>> context = super(PostListView, self).get_context_data(**kwargs)
>>> context['posts'][0].likes.filter(id=self.request.user.id).exists
>>> ()
>>> is_liked = False
>>> if post.likes.filter(id=self.request.user.id).exists():
>>> is_liked = True
>>> context = {'post': post,
>>>'is_like': is_liked,
>>>}
>>> return context
>>>
>>>
>>>
>>> def like_post(request):
>>> post = get_object_or_404(Post, id=request.POST.get('post_id'))
>>> is_liked = False
>>> if post.likes.filter(id=request.user.id).exists():
>>> posts.likes.remove(request.user)
>>> is_liked = False
>>>
>>> else:
>>> post.likes.add(request.user)
>>> is_liked = True
>>>
>>> return HttpResponseRedirect(post.get_absolute_url())
>>>
>>>
>>> This is the model
>>>
>>>
>>> class Post(models.Model):
>>> designer = models.ForeignKey(User, on_delete=models.CASCADE)
>>> title = models.CharField(max_length=100)
>>> date_posted = models.DateTimeField(default=timezone.now)
>>> likes = models.ManyToManyField(User, blank=True, related_name='likes')
>>>
>>> def __str__(self):
>>> return self.title
>>>
>>> Here is the
>>>
>>> path('like/', like_post, name='like_post'),
>>>
>>> here is the template:
>>>
>>> {% extends "base.html"%} {% block content %} {% for post in posts %}
>>> {{post.title}}
>>> 
>>>   {% csrf_token %} {% if is_like %}
>>>   
>>>   Unlike
>>>   {% else %}
>>>   Like
>>>   {% endif %}Likes 
>>>
>>> {% endfor %} {% endblock content %}
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/583492d8-5252-4f86-8e8f-7593b582d404%40googlegroups.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/aee352a1-2938-42a6-98cb-5d602abba567%40googlegroups.com
> 

Re: Can I use a JS Framework to display small JS tasks in a Django project?

2020-05-13 Thread Derek
Its not clear why you need JS at all. The app can load content from 
directories on the server side (back-end) and write these to a DB.  Django 
could then load these from the DB and show in the normal way.  Page 
generation can be done via normal views (Django/Python code).

(PS Both react and angular are not "new" - each are over 6 years old; more 
than 2 generations of computer science students...)


On Tuesday, 12 May 2020 16:04:55 UTC+2, Alexander Rogowski wrote:
>
> I have an idea to simplify the online experiments from our university. But 
> I'm not so familiar with the newest FE frameworks eg. react, angular, vue. 
> Any answer on this post is appreciated :)
>
> The idea is, to put our experiments in two folders, "tasks" and 
> "treatments". A task could be something trivial like put some sliders on 
> the right position or write with a chatbot (this should be coded in js, I 
> guess?) and in treatments could be something like collecting badges or the 
> setting for the chatbot (e.g. human-like/machine-like).
>
> My question is: Can I use a JS Framework to load the content from the two 
> directories and show them as options on a main page? After selecting the 
> task and the treatments, it would generate a page with the selected items, 
> e.g. the chatbot with the human-like setting.
>
> I Would like to do this with Django (because I already worked with it) so 
> we can create unique links to send them to the probands. Is Django with a 
> JS Framework the right decision? How would you approach the problem?
>

-- 
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/d673c088-20f0-40a7-916e-346979e55a71%40googlegroups.com.


Re: Deploying Django Project on heroku

2020-05-13 Thread Akshat Zala
If using django3.0.0, please  down grade the django.VERSION to django==2.2

On Wednesday, 13 May 2020 20:46:17 UTC+5:30, Akshat Zala wrote:
>
> Which version of django are you using?
>
> On Saturday, 9 May 2020 19:21:53 UTC+5:30, Sunday Iyanu Ajayi wrote:
>>
>> I have but I still get error
>>
>> [image: image.png]
>> *AJAYI Sunday *
>> (+234) 806 771 5394
>> *sunne...@gmail.com*
>>
>>
>>
>> On Sat, May 9, 2020 at 1:50 PM ola neat  wrote:
>>
>>> Halo, i feel if u follow the step in this article 
>>> https://www.codementor.io/@jamesezechukwu/how-to-deploy-django-app-on-heroku-dtsee04d4
>>>  
>>> u should b good 
>>>
>>> On Sat, May 9, 2020, 01:15 Sunday Iyanu Ajayi  
>>> wrote:
>>>
 Hi Motaz, 
 Thank you so much.
 Is today cool?
 What time (in GMT+1) will be cool for you?

 *AJAYI Sunday *
 (+234) 806 771 5394
 *sunne...@gmail.com*



 On Sun, May 3, 2020 at 11:05 PM Motaz Hejaze  wrote:

> Let us have a zoom meeting to fix it
>
> On Sun, 3 May 2020, 11:45 pm Sunday Iyanu Ajayi,  
> wrote:
>
>> I have but it keeps telling  that it is misconfigured 
>> *AJAYI Sunday *
>> (+234) 806 771 5394
>> *sunne...@gmail.com*
>>
>>
>>
>> On Sat, Apr 25, 2020 at 3:17 PM sagar ninave  
>> wrote:
>>
>>> Do you installed whitenoise package 
>>> If not then run this command 
>>> Pip insatll whitenoise
>>>
>>> On Sat, 25 Apr 2020 at 7:43 PM, Sunday Iyanu Ajayi <
>>> sunne...@gmail.com> wrote:
>>>
 I have spent over 2weeks on deploying a django project to heroku 
 but I keep getting error messages such as :

 My WhiteNoise is not configured  and I have followed all the 
 tutorials recommended  and yet same thing.

 Please who has a guide I can follow that is very updated.
 Thank you.
 *AJAYI Sunday *
 (+234) 806 771 5394
 *sunne...@gmail.com*

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

>>> -- 
>>>
>>> 
>>>  
>>> sagar ninave
>>> about.me/sagarninave 
>>> 
>>>  
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, 
>>> send an email to django...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAA6pdZ9fsGj3y%3DNVVQ_oCX9hY5DbLHtPVLM-nPhWYxpE4Qsi7w%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google 
>> Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, 
>> send an email to django...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAKYSAw2hYQGRYYZRB%3D7ZNJJJ-1OY2ykShsPam9xiRc-8M4BQJg%40mail.gmail.com
>>  
>> 
>> .
>>
> -- 
> You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to django...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAHV4E-dLr30ycFTo9tccTmKW74rvDA%3D0Oks8NqAVez0Tiyzocg%40mail.gmail.com
>  
> 
> .
>
 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it,

Re: Deploying Django Project on heroku

2020-05-13 Thread Akshat Zala
Which version of django are you using?

On Saturday, 9 May 2020 19:21:53 UTC+5:30, Sunday Iyanu Ajayi wrote:
>
> I have but I still get error
>
> [image: image.png]
> *AJAYI Sunday *
> (+234) 806 771 5394
> *sunne...@gmail.com *
>
>
>
> On Sat, May 9, 2020 at 1:50 PM ola neat > 
> wrote:
>
>> Halo, i feel if u follow the step in this article 
>> https://www.codementor.io/@jamesezechukwu/how-to-deploy-django-app-on-heroku-dtsee04d4
>>  
>> u should b good 
>>
>> On Sat, May 9, 2020, 01:15 Sunday Iyanu Ajayi > > wrote:
>>
>>> Hi Motaz, 
>>> Thank you so much.
>>> Is today cool?
>>> What time (in GMT+1) will be cool for you?
>>>
>>> *AJAYI Sunday *
>>> (+234) 806 771 5394
>>> *sunne...@gmail.com *
>>>
>>>
>>>
>>> On Sun, May 3, 2020 at 11:05 PM Motaz Hejaze >> > wrote:
>>>
 Let us have a zoom meeting to fix it

 On Sun, 3 May 2020, 11:45 pm Sunday Iyanu Ajayi, >>> > wrote:

> I have but it keeps telling  that it is misconfigured 
> *AJAYI Sunday *
> (+234) 806 771 5394
> *sunne...@gmail.com *
>
>
>
> On Sat, Apr 25, 2020 at 3:17 PM sagar ninave  > wrote:
>
>> Do you installed whitenoise package 
>> If not then run this command 
>> Pip insatll whitenoise
>>
>> On Sat, 25 Apr 2020 at 7:43 PM, Sunday Iyanu Ajayi <
>> sunne...@gmail.com > wrote:
>>
>>> I have spent over 2weeks on deploying a django project to heroku but 
>>> I keep getting error messages such as :
>>>
>>> My WhiteNoise is not configured  and I have followed all the 
>>> tutorials recommended  and yet same thing.
>>>
>>> Please who has a guide I can follow that is very updated.
>>> Thank you.
>>> *AJAYI Sunday *
>>> (+234) 806 771 5394
>>> *sunne...@gmail.com *
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, 
>>> send an email to django...@googlegroups.com .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAKYSAw2PsC452Sk5_1e_sMy3HuZ3zWrFh5p6CVn6K-KsVF1Rqg%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>> -- 
>>
>> 
>>  
>> sagar ninave
>> about.me/sagarninave 
>> 
>>  
>>
>> -- 
>> You received this message because you are subscribed to the Google 
>> Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, 
>> send an email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAA6pdZ9fsGj3y%3DNVVQ_oCX9hY5DbLHtPVLM-nPhWYxpE4Qsi7w%40mail.gmail.com
>>  
>> 
>> .
>>
> -- 
> You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to django...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAKYSAw2hYQGRYYZRB%3D7ZNJJJ-1OY2ykShsPam9xiRc-8M4BQJg%40mail.gmail.com
>  
> 
> .
>
 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django...@googlegroups.com .
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/CAHV4E-dLr30ycFTo9tccTmKW74rvDA%3D0Oks8NqAVez0Tiyzocg%40mail.gmail.com
  
 
 .

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

Viewing available functions and variables

2020-05-13 Thread Clive Bruton
I am using django-allauth for a user registration/log-in system. I  
have this working, however, as a general question, I would like to  
understand how one can view the functions/variables available on a  
given template.


For example I see that in some templates these are included:

{% user_display confirmation.email_address.user as user_display %}

{{ emailaddress.email }}

But I cannot, for example, access these in templates used for sending  
email.


Hope that is clear.


-- Clive

--
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/309D6173-2B9B-4A48-B5FD-2104BA33C1E2%40indx.co.uk.


Re: install Microsoft visual C ++ 14.0 to be able to use mysqlclient in my Django projects

2020-05-13 Thread Sundararajan Seshadri
Try https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

Cheers

On Saturday, May 9, 2020 at 10:24:56 PM UTC+5:30, Anselme SERI wrote:
>
> [image: nscreen.jpg]
> Hello, I have been struggling for a few days wanting to install Microsoft 
> visual C ++ 14.0 to be able to use mysqlclient in my Django projects. I use 
> Win10, Python 3.8.2 and Django 3.0.5. Has anyone ever encountered this 
> problem and solved it? I need help.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/80847619-1344-4833-94bf-7cd031dc6cb3%40googlegroups.com.


Re: help with my signup api

2020-05-13 Thread Vijay Khemlani
in your code data is json.dumps(request.data), which is a string
representation of the json dictionary

so data is a str and then you are trying to do item assignment to it

On Wed, May 13, 2020 at 8:05 AM ola neat  wrote:

> good day guys, please i need help with my signup api, when the user click
> signup i get this err msg "TypeError: 'str' object does not support item
> assignment", in my CLI, which as a result display err msg to the user, but
> eventually the user get created. i got the code and err msg attached below
> thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHLKn72ZwUjSgHCDxLdu4C6wcg_zv8N%2Brx4EnmFySmcyLHPG7w%40mail.gmail.com
> 
> .
>

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


Re: CSS with Django forms

2020-05-13 Thread Kasper Laudrup




On 13/05/2020 06.17, Bighnesh Pradhan wrote:

you can use javascript it is good



Oh yes, we all love javascript:

https://www.destroyallsoftware.com/talks/wat

:-)

Seriously though, javascript has nothing to do with using static CSS in 
django templates.


--
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/322f8ce6-7dc3-0e9c-0fcf-1b1135011698%40stacktrace.dk.


Re: CSS with Django forms

2020-05-13 Thread Clive Bruton



On 12 May 2020, at 22:41, Anubhav Madhav wrote:


Is there any way to display the forms with my HTML CSS files.


Use {% include %} (https://docs.djangoproject.com/en/3.0/ref/ 
templates/builtins/#include) in your HTML template files for an  
embedded style sheet, or just use a link in the head of your template  
to serve the .css from the "static" folder (or other remote server  
location).



-- Clive

--
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/33DABBFA-7A36-42B0-9B9B-05C29ADEA7C9%40indx.co.uk.


Re: CSS with Django forms

2020-05-13 Thread Bighnesh Pradhan
you can use javascript it is good

On Wed, May 13, 2020 at 3:13 AM Anubhav Madhav 
wrote:

> My problem is, that I've made a beautiful 'Sign Up' and 'Login' Page using
> HTML and CSS. Later on, in my project, I had to use 'forms' for
> registration and login.
> Is there any way to display the forms with my HTML CSS files.
> Please Help!!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d53c8101-9243-47b2-9ca5-a727888034ca%40googlegroups.com
> 
> .
>

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


How to test get_success_url method in class based view

2020-05-13 Thread Sumit Kumar
Hey, everyone. Please help me in this problem, i'm trying to test the 
get_success_url method, but didn't got success.

https://stackoverflow.com/questions/61745172/how-to-test-get-success-url-in-classbasedview-for-django

-- 
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/a3e186a0-511c-4f17-b8f9-742cfc6392dc%40googlegroups.com.


Re: How to over ride the get context data method in view

2020-05-13 Thread Ahmed Khairy
Hi Andréas Kühne,

Regarding the first error

I have a list of posts in the listView and want to add the like button to 
each post so how should I fix it? 

Thank you 

On Wednesday, May 13, 2020 at 6:08:31 AM UTC-4, Andréas Kühne wrote:
>
> Hi,
>
> There are a couple of errors in your code:
>
> 1. You are using a ListView and then trying to get an individual post? 
> That is really strange
> 2. In your get_context_data method - you first get the context data, 
> update it and then you set it to a new dict, so everything is reset in the 
> dict.
> 3. you are trying to get the absolut url for your post, but aren't showing 
> any post detail view.
>
> Regards,
>
> Andréas
>
>
> Den ons 13 maj 2020 kl 06:46 skrev Ahmed Khairy  >:
>
>> I am currently trying to create a like button for my posts in Django
>>
>> I have reached to the part where I can add a like but I am facing 
>> difficulty writing the code related to the view which linking the 
>> PostListView if there is user who liked it or not. I am getting an error: 
>> page Error 404 although everything is correct
>>
>>
>> this the views: 
>>
>>
>> class PostListView(ListView):
>> model = Post
>> template_name = "score.html"
>> ordering = ['-date_posted']
>> context_object_name = 'posts'
>> queryset = Post.objects.filter(admin_approved=True)
>> paginate_by = 5
>>
>> def get_context_data(self, **kwargs):
>> post = get_object_or_404(Post, id=self.request.POST.get('post_id'
>> ))
>> context = super(PostListView, self).get_context_data(**kwargs)
>> context['posts'][0].likes.filter(id=self.request.user.id).exists
>> ()
>> is_liked = False
>> if post.likes.filter(id=self.request.user.id).exists():
>> is_liked = True
>> context = {'post': post,
>>'is_like': is_liked,
>>}
>> return context
>>
>>
>>
>> def like_post(request):
>> post = get_object_or_404(Post, id=request.POST.get('post_id'))
>> is_liked = False
>> if post.likes.filter(id=request.user.id).exists():
>> posts.likes.remove(request.user)
>> is_liked = False
>>
>> else:
>> post.likes.add(request.user)
>> is_liked = True
>>
>> return HttpResponseRedirect(post.get_absolute_url())
>>
>>
>> This is the model 
>>
>>
>> class Post(models.Model):
>> designer = models.ForeignKey(User, on_delete=models.CASCADE)
>> title = models.CharField(max_length=100)
>> date_posted = models.DateTimeField(default=timezone.now)
>> likes = models.ManyToManyField(User, blank=True, related_name='likes')
>>
>> def __str__(self):
>> return self.title
>>
>> Here is the
>>
>> path('like/', like_post, name='like_post'),
>>
>> here is the template: 
>>
>> {% extends "base.html"%} {% block content %} {% for post in posts %}
>> {{post.title}}
>> 
>>   {% csrf_token %} {% if is_like %}
>>   
>>   Unlike
>>   {% else %}
>>   Like
>>   {% endif %}Likes 
>>
>> {% endfor %} {% endblock content %} 
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/583492d8-5252-4f86-8e8f-7593b582d404%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aee352a1-2938-42a6-98cb-5d602abba567%40googlegroups.com.


Re: How to over ride the get context data method in view

2020-05-13 Thread Andréas Kühne
Hi,

There are a couple of errors in your code:

1. You are using a ListView and then trying to get an individual post? That
is really strange
2. In your get_context_data method - you first get the context data, update
it and then you set it to a new dict, so everything is reset in the dict.
3. you are trying to get the absolut url for your post, but aren't showing
any post detail view.

Regards,

Andréas


Den ons 13 maj 2020 kl 06:46 skrev Ahmed Khairy :

> I am currently trying to create a like button for my posts in Django
>
> I have reached to the part where I can add a like but I am facing
> difficulty writing the code related to the view which linking the
> PostListView if there is user who liked it or not. I am getting an error:
> page Error 404 although everything is correct
>
>
> this the views:
>
>
> class PostListView(ListView):
> model = Post
> template_name = "score.html"
> ordering = ['-date_posted']
> context_object_name = 'posts'
> queryset = Post.objects.filter(admin_approved=True)
> paginate_by = 5
>
> def get_context_data(self, **kwargs):
> post = get_object_or_404(Post, id=self.request.POST.get('post_id'
> ))
> context = super(PostListView, self).get_context_data(**kwargs)
> context['posts'][0].likes.filter(id=self.request.user.id).exists()
> is_liked = False
> if post.likes.filter(id=self.request.user.id).exists():
> is_liked = True
> context = {'post': post,
>'is_like': is_liked,
>}
> return context
>
>
>
> def like_post(request):
> post = get_object_or_404(Post, id=request.POST.get('post_id'))
> is_liked = False
> if post.likes.filter(id=request.user.id).exists():
> posts.likes.remove(request.user)
> is_liked = False
>
> else:
> post.likes.add(request.user)
> is_liked = True
>
> return HttpResponseRedirect(post.get_absolute_url())
>
>
> This is the model
>
>
> class Post(models.Model):
> designer = models.ForeignKey(User, on_delete=models.CASCADE)
> title = models.CharField(max_length=100)
> date_posted = models.DateTimeField(default=timezone.now)
> likes = models.ManyToManyField(User, blank=True, related_name='likes')
>
> def __str__(self):
> return self.title
>
> Here is the
>
> path('like/', like_post, name='like_post'),
>
> here is the template:
>
> {% extends "base.html"%} {% block content %} {% for post in posts %}
> {{post.title}}
> 
>   {% csrf_token %} {% if is_like %}
>   
>   Unlike
>   {% else %}
>   Like
>   {% endif %}Likes 
>
> {% endfor %} {% endblock content %}
>
>
> --
> 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/583492d8-5252-4f86-8e8f-7593b582d404%40googlegroups.com
> 
> .
>

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


Re: hi eveyone

2020-05-13 Thread Joshua Kayode
Hello

On Tue, May 12, 2020, 3:06 PM Ravindra Patil  wrote:

> hi eveyone
>
> --
> 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/4c97da5b-f60f-4f9a-973d-3953c7b9cc1f%40googlegroups.com
> 
> .
>

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