Skip to content

Commit 11d4c9f

Browse files
committed
Code snippets
1 parent 16bd511 commit 11d4c9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1224
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Mac
2+
.DS_Store
3+
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
pip-wheel-metadata/
27+
share/python-wheels/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
MANIFEST
32+
33+
# PyInstaller
34+
# Usually these files are written by a python script from a template
35+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36+
*.manifest
37+
*.spec
38+
39+
# Installer logs
40+
pip-log.txt
41+
pip-delete-this-directory.txt
42+
43+
# Unit test / coverage reports
44+
htmlcov/
45+
.tox/
46+
.nox/
47+
.coverage
48+
.coverage.*
49+
.cache
50+
nosetests.xml
51+
coverage.xml
52+
*.cover
53+
.hypothesis/
54+
.pytest_cache/
55+
56+
# Translations
57+
*.mo
58+
*.pot
59+
60+
# Django stuff:
61+
*.log
62+
local_settings.py
63+
db.sqlite3
64+
65+
# Flask stuff:
66+
instance/
67+
.webassets-cache
68+
69+
# Scrapy stuff:
70+
.scrapy
71+
72+
# Sphinx documentation
73+
docs/_build/
74+
75+
# PyBuilder
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
.python-version
87+
88+
# celery beat schedule file
89+
celerybeat-schedule
90+
91+
# SageMath parsed files
92+
*.sage.py
93+
94+
# Environments
95+
.env
96+
.venv
97+
env/
98+
venv/
99+
ENV/
100+
env.bak/
101+
venv.bak/
102+
103+
# Spyder project settings
104+
.spyderproject
105+
.spyproject
106+
107+
# Rope project settings
108+
.ropeproject
109+
110+
# mkdocs documentation
111+
/site
112+
113+
# mypy
114+
.mypy_cache/
115+
.dmypy.json
116+
dmypy.json
117+
118+
# Pyre type checker
119+
.pyre/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: gunicorn django_project.wsgi

Django_Blog/13-Deployment-Heroku/django_project/blog/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from django.contrib import admin
2+
from .models import Post
3+
4+
admin.site.register(Post)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BlogConfig(AppConfig):
5+
name = 'blog'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 2.1 on 2018-08-28 02:32
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
import django.db.models.deletion
6+
import django.utils.timezone
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
initial = True
12+
13+
dependencies = [
14+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
15+
]
16+
17+
operations = [
18+
migrations.CreateModel(
19+
name='Post',
20+
fields=[
21+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
22+
('title', models.CharField(max_length=100)),
23+
('content', models.TextField()),
24+
('date_posted', models.DateTimeField(default=django.utils.timezone.now)),
25+
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
26+
],
27+
),
28+
]

Django_Blog/13-Deployment-Heroku/django_project/blog/migrations/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from django.db import models
2+
from django.utils import timezone
3+
from django.contrib.auth.models import User
4+
from django.urls import reverse
5+
6+
7+
class Post(models.Model):
8+
title = models.CharField(max_length=100)
9+
content = models.TextField()
10+
date_posted = models.DateTimeField(default=timezone.now)
11+
author = models.ForeignKey(User, on_delete=models.CASCADE)
12+
13+
def __str__(self):
14+
return self.title
15+
16+
def get_absolute_url(self):
17+
return reverse('post-detail', kwargs={'pk': self.pk})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
body {
2+
background: #fafafa;
3+
color: #333333;
4+
margin-top: 5rem;
5+
}
6+
7+
h1, h2, h3, h4, h5, h6 {
8+
color: #444444;
9+
}
10+
11+
ul {
12+
margin: 0;
13+
}
14+
15+
.bg-steel {
16+
background-color: #5f788a;
17+
}
18+
19+
.site-header .navbar-nav .nav-link {
20+
color: #cbd5db;
21+
}
22+
23+
.site-header .navbar-nav .nav-link:hover {
24+
color: #ffffff;
25+
}
26+
27+
.site-header .navbar-nav .nav-link.active {
28+
font-weight: 500;
29+
}
30+
31+
.content-section {
32+
background: #ffffff;
33+
padding: 10px 20px;
34+
border: 1px solid #dddddd;
35+
border-radius: 3px;
36+
margin-bottom: 20px;
37+
}
38+
39+
.article-title {
40+
color: #444444;
41+
}
42+
43+
a.article-title:hover {
44+
color: #428bca;
45+
text-decoration: none;
46+
}
47+
48+
.article-content {
49+
white-space: pre-line;
50+
}
51+
52+
.article-img {
53+
height: 65px;
54+
width: 65px;
55+
margin-right: 16px;
56+
}
57+
58+
.article-metadata {
59+
padding-bottom: 1px;
60+
margin-bottom: 4px;
61+
border-bottom: 1px solid #e3e3e3
62+
}
63+
64+
.article-metadata a:hover {
65+
color: #333;
66+
text-decoration: none;
67+
}
68+
69+
.article-svg {
70+
width: 25px;
71+
height: 25px;
72+
vertical-align: middle;
73+
}
74+
75+
.account-img {
76+
height: 125px;
77+
width: 125px;
78+
margin-right: 20px;
79+
margin-bottom: 16px;
80+
}
81+
82+
.account-heading {
83+
font-size: 2.5rem;
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% extends "blog/base.html" %}
2+
{% block content %}
3+
<h1>About Page</h1>
4+
{% endblock content %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{% load static %}
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
6+
<!-- Required meta tags -->
7+
<meta charset="utf-8">
8+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
9+
10+
<!-- Bootstrap CSS -->
11+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
12+
13+
<link rel="stylesheet" type="text/css" href="{% static 'blog/main.css' %}">
14+
15+
{% if title %}
16+
<title>Django Blog - {{ title }}</title>
17+
{% else %}
18+
<title>Django Blog</title>
19+
{% endif %}
20+
</head>
21+
<body>
22+
<header class="site-header">
23+
<nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
24+
<div class="container">
25+
<a class="navbar-brand mr-4" href="{% url 'blog-home' %}">Django Blog</a>
26+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
27+
<span class="navbar-toggler-icon"></span>
28+
</button>
29+
<div class="collapse navbar-collapse" id="navbarToggle">
30+
<div class="navbar-nav mr-auto">
31+
<a class="nav-item nav-link" href="{% url 'blog-home' %}">Home</a>
32+
<a class="nav-item nav-link" href="{% url 'blog-about' %}">About</a>
33+
</div>
34+
<!-- Navbar Right Side -->
35+
<div class="navbar-nav">
36+
{% if user.is_authenticated %}
37+
<a class="nav-item nav-link" href="{% url 'post-create' %}">New Post</a>
38+
<a class="nav-item nav-link" href="{% url 'profile' %}">Profile</a>
39+
<a class="nav-item nav-link" href="{% url 'logout' %}">Logout</a>
40+
{% else %}
41+
<a class="nav-item nav-link" href="{% url 'login' %}">Login</a>
42+
<a class="nav-item nav-link" href="{% url 'register' %}">Register</a>
43+
{% endif %}
44+
</div>
45+
</div>
46+
</div>
47+
</nav>
48+
</header>
49+
<main role="main" class="container">
50+
<div class="row">
51+
<div class="col-md-8">
52+
{% if messages %}
53+
{% for message in messages %}
54+
<div class="alert alert-{{ message.tags }}">
55+
{{ message }}
56+
</div>
57+
{% endfor %}
58+
{% endif %}
59+
{% block content %}{% endblock %}
60+
</div>
61+
<div class="col-md-4">
62+
<div class="content-section">
63+
<h3>Our Sidebar</h3>
64+
<p class='text-muted'>You can put any information here you'd like.
65+
<ul class="list-group">
66+
<li class="list-group-item list-group-item-light">Latest Posts</li>
67+
<li class="list-group-item list-group-item-light">Announcements</li>
68+
<li class="list-group-item list-group-item-light">Calendars</li>
69+
<li class="list-group-item list-group-item-light">etc</li>
70+
</ul>
71+
</p>
72+
</div>
73+
</div>
74+
</div>
75+
</main>
76+
77+
<!-- Optional JavaScript -->
78+
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
79+
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
80+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
81+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
82+
</body>
83+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{% extends "blog/base.html" %}
2+
{% block content %}
3+
{% for post in posts %}
4+
<article class="media content-section">
5+
<img class="rounded-circle article-img" src="{{ post.author.profile.image.url }}">
6+
<div class="media-body">
7+
<div class="article-metadata">
8+
<a class="mr-2" href="{% url 'user-posts' post.author.username %}">{{ post.author }}</a>
9+
<small class="text-muted">{{ post.date_posted|date:"F d, Y" }}</small>
10+
</div>
11+
<h2><a class="article-title" href="{% url 'post-detail' post.id %}">{{ post.title }}</a></h2>
12+
<p class="article-content">{{ post.content }}</p>
13+
</div>
14+
</article>
15+
{% endfor %}
16+
{% if is_paginated %}
17+
18+
{% if page_obj.has_previous %}
19+
<a class="btn btn-outline-info mb-4" href="?page=1">First</a>
20+
<a class="btn btn-outline-info mb-4" href="?page={{ page_obj.previous_page_number }}">Previous</a>
21+
{% endif %}
22+
23+
{% for num in page_obj.paginator.page_range %}
24+
{% if page_obj.number == num %}
25+
<a class="btn btn-info mb-4" href="?page={{ num }}">{{ num }}</a>
26+
{% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
27+
<a class="btn btn-outline-info mb-4" href="?page={{ num }}">{{ num }}</a>
28+
{% endif %}
29+
{% endfor %}
30+
31+
{% if page_obj.has_next %}
32+
<a class="btn btn-outline-info mb-4" href="?page={{ page_obj.next_page_number }}">Next</a>
33+
<a class="btn btn-outline-info mb-4" href="?page={{ page_obj.paginator.num_pages }}">Last</a>
34+
{% endif %}
35+
36+
{% endif %}
37+
{% endblock content %}

0 commit comments

Comments
 (0)