質問編集履歴

1

現在作成中のコードを追加し、質問の内容を変更します。

2017/09/04 07:31

投稿

am120sec
am120sec

スコア14

test CHANGED
@@ -1 +1 @@
1
- Djangoでwysiwygを自作したい。
1
+ Djangoでwysiwyg(quill)使用する方法
test CHANGED
@@ -7,3 +7,263 @@
7
7
  wysiwygで作成した部分はHTMLタグを含めtextfieldに格納すればよいのでしょうか。
8
8
 
9
9
  参考になるサイト等があれば教えてください。
10
+
11
+
12
+
13
+ 2017/9/4 追記
14
+
15
+ 現在作成中のコードを追加し、質問の内容を変更します。
16
+
17
+
18
+
19
+ 1. quill(リッチテキストエディタ)上でアップロードする画像をどのようにしてDjangoと連携すればよいか
20
+
21
+ 2. quillで作成するリッチテキストエディタのフィールドはtext = models.TextField()でよいか
22
+
23
+ 3. HTMLでフォームのデータを取得し、表示する場合、{{post.quill}}のようにして、リッチテキストフィールドを呼び出せるか
24
+
25
+
26
+
27
+ 現在はDjangoで作成した、ただのテキストフォーム、画像の保存、表示は可能な状態ですが
28
+
29
+ 以上の質問内容の段階で手間取っている状況となります。
30
+
31
+
32
+
33
+ ご教授のほどよろしくお願い致します。
34
+
35
+
36
+
37
+ ```HTML
38
+
39
+ <!--index.html -->
40
+
41
+
42
+
43
+ {% load staticfiles %}
44
+
45
+ <!DOCTYPE html>
46
+
47
+ <html lang="ja">
48
+
49
+ <html>
50
+
51
+ <head>
52
+
53
+ <meta charset=utf-8 />
54
+
55
+ <link rel="stylesheet" href="{% static 'css/jquery-ui-1.12.1.css' %}">
56
+
57
+ <link rel="stylesheet" href="https://cdn.quilljs.com/1.3.1/quill.snow.css"/>
58
+
59
+ </head>
60
+
61
+ <body>
62
+
63
+ <form action= "{% url 'app:index' %}" method="POST" class="post-form" enctype="multipart/form-data">{% csrf_token %}
64
+
65
+ <p>{{ form1.toukou }}</p>
66
+
67
+ <p>{{ form1.tensuu }}</p>
68
+
69
+ <div id="standalone-container">
70
+
71
+ <div id="toolbar-container">
72
+
73
+ <span class="ql-formats">
74
+
75
+ <button class="ql-header" value="2"></button>
76
+
77
+ <button class="ql-blockquote"></button>
78
+
79
+ </span>
80
+
81
+ <span class="ql-formats">
82
+
83
+ <button class="ql-link"></button>
84
+
85
+ <button class="ql-image"></button>
86
+
87
+ <button class="ql-video"></button>
88
+
89
+ </span>
90
+
91
+ </div>
92
+
93
+ <div id="editor-container"></div>
94
+
95
+ </div>
96
+
97
+
98
+
99
+ <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.js"></script>
100
+
101
+ <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
102
+
103
+ <script type="text/javascript" src="https://cdn.quilljs.com/1.3.1/quill.min.js"></script>
104
+
105
+ <script type="text/javascript">
106
+
107
+ var quill = new Quill('#editor-container', {
108
+
109
+ modules: {
110
+
111
+ formula: true,
112
+
113
+ syntax: true,
114
+
115
+ toolbar: '#toolbar-container'
116
+
117
+ },
118
+
119
+ placeholder: 'ここに入力',
120
+
121
+ theme: 'snow'
122
+
123
+ });
124
+
125
+ </script>
126
+
127
+
128
+
129
+ <p><button type="submit" class="save btn btn-default">Save</button></p>
130
+
131
+ </form>
132
+
133
+ </body>
134
+
135
+ ```
136
+
137
+
138
+
139
+ ```Django
140
+
141
+ # model.py
142
+
143
+
144
+
145
+ from django.db import models
146
+
147
+ from django.utils import timezone
148
+
149
+
150
+
151
+ TENSUU_CHOICES = [(i,str(i)) for i in range(1, 11)]
152
+
153
+ class Action(models.Model):
154
+
155
+ #target = models.ForeignKey('Title_Post')
156
+
157
+ text = models.TextField()
158
+
159
+ author = models.ForeignKey('auth.User')
160
+
161
+ tensuu = models.DecimalField(max_digits=2,decimal_places=0,choices=TENSUU_CHOICES)
162
+
163
+ thumnail = models.ImageField(upload_to='static/images/', null=True, blank=True)
164
+
165
+ published_date = models.DateTimeField(blank=True, null=True)
166
+
167
+ def publish(self):
168
+
169
+ self.published_date = timezone.now()
170
+
171
+ self.save()
172
+
173
+ def __str__(self):
174
+
175
+ return self.text
176
+
177
+ ```
178
+
179
+
180
+
181
+ ```Django
182
+
183
+ # view.py
184
+
185
+
186
+
187
+ from django.shortcuts import render,redirect,render, get_object_or_404
188
+
189
+ from django.contrib.auth.decorators import login_required
190
+
191
+ from django.views.decorators.http import require_POST
192
+
193
+ from django.utils import timezone
194
+
195
+ from .models import Action
196
+
197
+ from .forms import Action_Form
198
+
199
+ from django.http import HttpResponse
200
+
201
+ from django.http import JsonResponse
202
+
203
+ from django.core import serializers
204
+
205
+ import json
206
+
207
+
208
+
209
+ def index(request):
210
+
211
+ posts = Action.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')
212
+
213
+ if request.method == "POST":
214
+
215
+ f = Action_Form(request.POST,request.FILES)
216
+
217
+ if f.is_valid():
218
+
219
+ post = f.save(commit=False)
220
+
221
+ post.author = request.user
222
+
223
+ post.published_date = timezone.now()
224
+
225
+ post.save()
226
+
227
+ return redirect('app:index')
228
+
229
+ else:
230
+
231
+ f = Action_Form()
232
+
233
+ return render(request, 'app/index.html', {'posts': posts,'form1':f})
234
+
235
+
236
+
237
+ ```
238
+
239
+
240
+
241
+ ```Django
242
+
243
+ # form.py
244
+
245
+
246
+
247
+ from django import forms
248
+
249
+ from .models import Action,Title_Post,Status
250
+
251
+
252
+
253
+ class Action_Form(forms.ModelForm):
254
+
255
+ thumnail = forms.FileField(label='Select a image.',required=False, )
256
+
257
+ class Meta:
258
+
259
+ model = Action
260
+
261
+ fields = ('tensuu','text','thumnail',)
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+ ```