Comment system in class based view in django showing error

2020-06-07 Thread Ali Ahammad


the basic source files are here : 
https://pastebin.pl/view/a0a1fc38  and i am trying to do it in class based 
view for further upgrade. My main project is written in class based view 
and it will be easy to integrate for me.

views.py codes are give below:

from .models import Post,Comment
from .forms import CommentForm
from django.shortcuts import render, get_object_or_404
from django.views.generic import ListView,DetailView
from django.shortcuts import redirect,render, get_object_or_404
from django.http import HttpResponseRedirect

class PostList(ListView):
model=Post
template_name='home.html'
context_object_name='post_list'
queryset=Post.objects.all()

class PostDetail(DetailView):
model=Post

def get_queryset(self):
queryset = super(PostDetail, self).get_queryset()
post=Post.objects.all()
comments=Comment.objects.filter(post=post)
return queryset

def get_context_data(self, **kwargs):
context = super(PostDetail, self).get_context_data(**kwargs)
if request.method == "POST":
comment_form = CommentForm(request.POST or None)
if comment_form.is_valid():
comment=comment_form.save(commit=False)
comment.post=post
comment.save()
else:
comment_form = CommentForm()
context['post']=post.objects.all()
context['comments']=comments.objects.all()
context['comment_form']=comment_form()
template_name='Post_detail.html'
return render(request, template_name, context)

when i execute the runserver it shows NameError at /post/1/ name 'request' 
is not defined

the models.py is:

from django.db import models
from django.contrib.auth.models import User

class Post(models.Model):
title = models.CharField(max_length=200, unique=True)
author = models.ForeignKey(User, on_delete= 
models.CASCADE,related_name='blog_posts')
content = models.TextField()

def __str__(self):
return self.title

class Comment(models.Model):
post = 
models.ForeignKey(Post,on_delete=models.CASCADE,related_name='comments')
name = models.CharField(max_length=80)
body = models.TextField()
reply=models.ForeignKey('Comment',on_delete=models.CASCADE,null=True)


def __str__(self):
return self.name

the function base view was:

def PostDetail(request,pk):
post = get_object_or_404(Post, pk=pk)
comments=Comment.objects.filter(post=post)
if request.method == "POST":
comment_form = CommentForm(request.POST or None)
if comment_form.is_valid():
comment=comment_form.save(commit=False)
comment.post=post
comment.save()
else:
comment_form = CommentForm()
context={
'post':post,
'comments':comments,
'comment_form':comment_form,
}
return render(request, 'post_detail.html', context)

that function base view was working fine but i am trying to convert it into 
class based view so that i can use custommixin and other mixin later on. 
how can i make it work?

please let me know. thanx in advance

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/17ba1d3b-8ed2-470f-9004-213357b2d403o%40googlegroups.com.


pagination of a specific context in multiple context in ListView not working in django?

2020-06-01 Thread Ali Ahammad
in django, i am trying to list some queries of several objects like user lists, 
categoies and Post list. the homepage will be contained couple of blocks or 
boxes. each box will have different query list like Post list, User List, 
category list. But only one context will have pagination and other won't and 
ofcourse the pagination will be working on Post list.

here is the views.py:

class BlogappListView(ListView):
model = Category,CustomUser
template_name = 'home.html'
context_object_name='category_list'
queryset=Category.objects.all()
paginate_by = 2

def get_context_data(self, **kwargs):
context = super(BlogappListView, self).get_context_data(**kwargs)
context['user_list']= CustomUser.objects.all()
context['post_list']=Post.objects.all()
activities=context['post_list']
return context
def get_related_activities(self,activities):
queryset=self.objects.activity_rel.all()
paginator=Paginator(queryset,2)
page=self.request.GET.get('page')
activities=paginator.get_page(page)
return(activities)
in urls.py:

urlpatterns = [
path('',BlogappListView.as_view(),name='home'),
]
in base.html, the paginate portion code:

  
  {% if is_paginated %}

{% if page_obj.has_previous %}
  
First
  
  
  Previous

{% endif %}

{% for num in page_obj.paginator.page_range %}
  {% if page_obj.number == num %}
  
{{ num 
}}
  

  {% elif num > page_obj.number|add:'-3' and num < 
page_obj.number|add:'3' %}
  
{{ num 
}}


  {% endif %}
{% endfor %}

{% if page_obj.has_next %}

  Next

  
  Last


{% endif %}

  {% endif %}

the main problem is that page number 1 is showing all the posts and also the 
second page. and category list is also truncated into 2 but the user list ok.

so how can i make it work ? is there any other way?

thank you in advance

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


Add search to my blog app

2020-05-20 Thread Ali Ahammad
At first you should make search search template where you should put what and 
how you want display

Then you should write a views.py function where you should use
query=request.GET[‘queer’]
Object_list=Post.objects.filter(title__icontains=query)
*same for the content If you want and then you should use union*
Return render(request,’search.html’,{ ‘object_list’:object_list,’query’:query})

Then in the sign.html use ur home.html or anything and write according to your 
requirement

You don’t need to use java

-- 
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/277d37ed-188f-4ad1-960a-e4f5eceee3d0%40googlegroups.com.


how to show blog posts according to categories and the list of categories in html template?

2020-05-20 Thread Ali Ahammad
0
1


i am trying to make site with django and want to categorize each post and a 
category list. in the category list every category name will be shown as a 
list and every category name will be linked to the posts according to their 
categories.

here is my *models.py*:

class Category(models.Model):
name=models.CharField(max_length=1000,null=True)
def __str__(self):
return self.nameclass Post(models.Model):
title=models.CharField(max_length=200,blank=True,null=True)

author=models.ForeignKey(get_user_model(),on_delete=models.CASCADE,null=True)
body=RichTextField(blank=True,null=True) 
image=models.FileField(upload_to="mediaphoto")

topImage=ImageSpecField(source='image',processors=[ResizeToFill(750,300)],format='PNG',options={'quality':60})
 
date=models.DateField(default=datetime.now, blank=True)
category = 
models.ForeignKey(Category,on_delete=models.CASCADE,verbose_name="Categories")  


def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('post_detail',args={str(self.id)})

here is my *views.py*:
def Categorylist(request):
categories = Category.objects.all()
return render (request, 'category_list.html', {'categories'
: categories})
def CategoryDetail(request,pk):
category = get_object_or_404(Category, pk=pk)

return render(request, 'post_category.html', {'Category': category})

here is my *urls.py*:

urlpatterns = [

path('post//delete/',BlogappDeleteView.as_view(),name='post_delete'),
path('post//edit/',BlogappUpdateView.as_view(),name='post_edit'),
path('post/new/', BlogappCreateview.as_view(),name='post_new'),
path('post//',BlogappPostView.as_view(),name='post_detail'), 
path('post//category', views.CategoryDetail, name='category'),
path('search',views.Search,name='search'),
path('',BlogappListView.as_view(),name='home'),
]

here is *post_category.html*

  {{ category.name }} Category{% for c in category %}{{post.title}}
{{post.description|truncatechars:400|safe}}
Read More 


Posted on {{post.date|safe}} by
{{post.author}}in {{post.category}}
  {% endfor %}

here is *category_list.html*:

{% for c in categories %}
  {{c.name}}{% endfor %}

main problem is that category list is not fetching any list from the 
Category name and when click on the category in a post below, it is not 
showing the posts related to this category. the category page is showing 
the category name post like physics category.

i think i messed up with the views.py query or in templates... will you 
help me on this please? it will be very much appreciated.

-- 
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/dbd7715a-7cec-4d0f-9f57-ed6746a71185%40googlegroups.com.


Re: How to resize image from Django ckeditor_uploader in the HTML template while rendering?

2020-05-18 Thread Ali Ahammad
thanx for your reply. i am using pillow in my profile app. but the main 
issue is with ckeditor_uploader as you know i have to use 
RichTextUploadingField(). besides it i have to mention in urls.py and i 
have to render it corresponding variable name in the template. my main goal 
was if i upload any picture in body=RichTextUploadingField() in 
localhost/admin, i want to render the image and the text contents 
separately. in this case i couldn't find any document where i can learn 
about it. i tried to use ckeditor widgets but it just customizing the 
ckeditor toolbar. i dun want this and i am happy with what i have for now.

so is there any way to render the uploading pic and resize and positioning 
in html template according to my own design? text can be separated and 
truncatchar:400 or 500 which i kew already. but i would like to separate 
the image from the text of the body. i hope you understand my problem

On Monday, May 18, 2020 at 12:49:53 PM UTC+1, Vishesh Mangla wrote:
>
> You can resize an image using the Pillow library or open-cv.
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *Ali Ahammad 
> *Sent: *17 May 2020 22:45
> *To: *Django users 
> *Subject: *How to resize image from Django ckeditor_uploader in the HTML 
> template while rendering?
>
>  
>
> I am using Django ckeditor_uploader to make a post view for a blog. But 
> while rendering in the template I wanted to render image separately from 
> the post content texts.
>
>  
>
> My main goal is to set the image separately on the template on top and 
> resizing it. And I can set more pictures inside the post  but the top one 
> will be highlighted and rendered in different HTML page.
>
>  
>
> Is there any way?
>
>  
>
> I tried to use ckeditor widget but it is just customizing the toolbar of 
> ckeditor
>
>  
>
> Please let me know if you have any idea 
>
>  
>
> -- 
>
> 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/4b148528-7b15-4d39-8763-5f3a0f1931b6%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/44ef45ba-68ce-4e08-a516-c7ff1a827ff5%40googlegroups.com.


How to resize image from Django ckeditor_uploader in the HTML template while rendering?

2020-05-17 Thread Ali Ahammad
I am using Django ckeditor_uploader to make a post view for a blog. But while 
rendering in the template I wanted to render image separately from the post 
content texts.

My main goal is to set the image separately on the template on top and resizing 
it. And I can set more pictures inside the post  but the top one will be 
highlighted and rendered in different HTML page.

Is there any way?

I tried to use ckeditor widget but it is just customizing the toolbar of 
ckeditor

Please let me know if you have any idea 

-- 
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/4b148528-7b15-4d39-8763-5f3a0f1931b6%40googlegroups.com.


Re: password reset pages are not showing customizing html file

2020-05-14 Thread Ali Ahammad
hello guys 

i have tried email_template_name = 'registration/password_reset_email.html', 
success_url = reverse_lazy('registration:password_reset_done') but still no 
luck. i tried to edit template_name='accounts/reset_password.html, seems 
like django is reaching out to this hml file. but when i delete all the 
code or kept all the code inside reset_password.html, it won't have any 
effect. seems like whtever i write it isn't rendering to base.html. what 
should be the effective solution?  

please help

On Wednesday, May 13, 2020 at 6:45:02 PM UTC+1, Ali Ahammad wrote:
>
> 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<
> button class="navbar-toggler" type="button"
> data-toggle="collapse" data-target="#navbarCollapse" 
> aria-controls="navbarCollapse" aria-expanded="false"
> aria-label="Toggle navigation">
> 
> 
> 
> {% if user.is_authenticated %}
> 
> 
>  "userMenu" data-toggle="dropdown"
> aria-haspopup="true" aria-expanded="false">
> {{ user.username }}
> 
>  aria-labelledby="userMenu">
>  "{% url 'password_reset'%}">Change password
> 
>  >
> Log Out
> 
> 
> 
> {% else %}
> 
>  "btn btn-outline-secondary">
> Log In
> 
> Sign up
> 
> {% endif %}
> 
> 
> 
> {% block content %}
> {% endblock content %}
> 
> 
> 
> https://code.jquery.com/jquery-3.3.1.slim.min.js&quot</a>; 
> integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4\
> YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous">
> https://cdnjs.cloudflare.com/ajax/libs/popper.js/\</a>
> 1.14.3/
&

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