ckeditor toolbar is not showing in html new post page.. why home.html (for adding a new post) is not showing the rendered django form for add new post?

234 views
Skip to first unread message

হজমুলা খান

unread,
Dec 12, 2019, 9:44:54 AM12/12/19
to Django users
i am integrating some apps to make a bigger project but the problem is when i try insert ckeditor in html login page it is not showing. for this reason i tried to make separate app is to see whats going on here. i am showing you the code in detail.
editing/settings.py:


..........
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'editor',
    'ckeditor_uploader',
    'ckeditor',
]
TEMPLATES = [
    {
       
        'DIRS': [os.path.join(BASE_DIR,'templates')],........
.....................
STATIC_URL = 'editor/static/'
STATIC_ROOT='editor/static/'
CKEDITOR_UPLOAD_PATH='editor/static/media/'

editing/urls.py:

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('editor.urls')),
    path('ckeditor/',include('ckeditor_uploader.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

in this case, my static folder is in editor/static when i execute python manage.py collectstatic and ckeditor folder is in editor/static directory also.

editor/models.py:

from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField

# Create your models here.

class Post(models.Model):
    title=models.CharField(max_length=255)
    body=models.CharField(max_length=2000)
    description=RichTextUploadingField()

    def __str__(self):
        return self.title

editor/admin.py:

from django.contrib import admin
from .models import Post

admin.site.register(Post)

when i execute python manage.py makemigrations and python manage.py migrate, ckeditor can be seen in locahost:8000/admin's new post section perfectly. then i tried to make templates.

base.html:
{% load static %}
<html>
<head>
<title>Django blog</title>
rel="stylesheet">
<link href="{% static 'admin/css/base.css' %}" rel="stylesheet">
</head>
<body>
<div>
<header>
<div class="nav-left">
<h1><a>Django blog</a></h1>
</div>
</header>
{% block content %}
{% endblock content %}
</div>
</body>
</html>

home.html:
{% extends 'base.html' %}
{% block content %}
<h1>New post</h1>
<form action="" method="post"enctype="multipart/form-data">
    
    {% csrf_token %}
        {{ form.media|safe }}
    {{ form.as_p }}
<input type="submit" value="Save" />
</form>
{% endblock content %}

and then i have created a html file editor/urls.py:
from django.urls import path

from .views import HomePageView

urlpatterns=[
    path('',HomePageView.as_view(), name='home'),
]

and here is the editor/views.py also:
from django.views.generic import TemplateView
from .models import Post


class HomePageView(TemplateView):
     model=Post
     template_name='home.html'
     fields=['title','body']

i just want to see a simple page of showing new html post editor with ckeditor toolbar in it. it's just for seeing what's wrong and why my ckeditor toolbar is not showing in my html file. when i run python manage.py runserver there is no error showing and the html page is showing django post and new post and only the save button. it can't render the form of the django's new post. css style is rendered because the django post and new post has the desired color and font. but why it is not rendering the new post form with ckeditor toolbar?

i am still learning and this problem is eating me up. thanx in advance


Integr@te System

unread,
Dec 12, 2019, 3:24:48 PM12/12/19
to django...@googlegroups.com
Hi,

Django view dont render csrf tag within template form, you should check doc in warning part

And look at the additional way to resolve your 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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b8c48a91-b67c-4da0-8ce3-b301798a3851%40googlegroups.com.

হজমুলা খান

unread,
Dec 12, 2019, 10:10:17 PM12/12/19
to Django users
thanx for your advice and i removed  {% csrf_token %} and still same. problem is not solved. add post form is not showing.

To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Integr@te System

unread,
Dec 13, 2019, 5:07:37 PM12/13/19
to django...@googlegroups.com
Hi Issuer,

Plz check docs again for resolve your matter.
Try either set csrf token cookies or use ensure_csrf_cookie()

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6001f99c-e97c-495a-910c-cb436734a610%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages