Created
May 12, 2018 14:18
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from .models import Post | |
admin.site.register(Post) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
... | |
}, | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
s
a