Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
from django.contrib import admin
from .models import Post
admin.site.register(Post)
from django.urls import path
from . import views
urlpatterns = [
# ex: /
path('', views.index, name='index'),
# ex: /5/
path('<int:post_id>/', views.detail, name='detail'),
]
# virtual env oluşturulması
# python 2.7 için
# virtualenv demo
# python3 için
python3 -m venv demo
# env'i aktif etmek için
. bin/activate
# env'i pasif etmek için
deactivate
# django kurulumu
pip install --upgrade pip
pip install django
# ilk proje
# test için python manage.py runserver 0:8081
django-admin startproject manisa .
# app
python manage.py startapp blog
# installed apps
INSTALLED_APPS = [
....
'blog.apps.BlogConfig',
...
]
python manage.py makemigrations
python manage.py migrate
from django.db import models
from django.utils import timezone
class Post(models.Model):
author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = [
...,
'blog',
...,
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'template')],
'APP_DIRS': True,
...
},
]
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('/', include('blog.urls')),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment