[image: Capture.JPG]
template:
  </li>
                <!-- Button trigger modal -->
                    <button type="button" class="btn btn-primary" 
data-toggle="modal" data-target="#exampleModal">
                      Bildiris bermek
                    </button>

                    <!-- Modal -->
                    <div class="modal fade" id="exampleModal" tabindex="-1" 
role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                      <div class="modal-dialog" role="document">
                        <div class="modal-content">
                          <div class="modal-header">
                            <h5 class="modal-title" 
id="exampleModalLabel">Modal title</h5>
                            <button type="button" class="close" 
data-dismiss="modal" aria-label="Close">
                              <span aria-hidden="true">&times;</span>
                            </button>
                          </div>
                          <div class="modal-body">
                            <form id="add_form">
                                {% csrf_token %}
                                {{ form }}
                            </form>
                          </div>
                          <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" 
data-dismiss="modal">Close</button>
                            <button id="add_form" type="submit" class="btn 
btn-primary">Save changes</button>
                          </div>
                        </div>
                      </div>
                    </div>
                </ul>
                <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="search" 
placeholder="Gözlet" aria-label="Gözlet">
                    <button class="btn btn-outline-success my-2 my-sm-0" 
type="submit">Gözlet</button>
                </form>
                </div>
                </nav>
                </div>
----------------------------------------------------

django form:

from django import forms
from .models import Post


class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = '__all__'


def __init__(self, *args, **kwargs):
super().__init__(*args,**kwargs)
for field in self.fields:
self.fields[field].widget['class'] = 'form-control'

----------------------------------------------------------------------------------------

django views:

from django.shortcuts import render
from .models import Post
from .forms import PostForm


def add_post(request):
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            form.save()
    template = 'home.html'
    context = {'form': PostForm(),}
    return render(request,template,context)

-----------------------------------------------------------------


django urls

from django.urls import path
from .import views

urlpatterns = [
    path('',views.home, name="home"),
    path('detail/<int:id>',views.detail_page, name="detail"),
    path('',views.add_post, name="home"),
]


----------------------------------------------------

django models:

from django.db import models


class Post(models.Model):
    title = models.CharField(max_length=50)
    date = models.DateTimeField(auto_now=True)
    text = models.TextField()


    class Meta:
        ordering = ('-date',)


    def __str__(self):
        return self.title



-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fa7e9ab5-974a-4752-be7d-b60b31277f88%40googlegroups.com.

Reply via email to