index, show, static files

master
Jerrica Bobadilla 5 years ago
parent eb11156301
commit b8c6793d19

1
.gitignore vendored

@ -0,0 +1 @@
.env

@ -8,6 +8,7 @@ verify_ssl = true
[packages] [packages]
django = "*" django = "*"
psycopg2-binary = "*" psycopg2-binary = "*"
django-extensions = "*"
[requires] [requires]
python_version = "3.8" python_version = "3.8"

10
Pipfile.lock generated

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "b04c44c86eca3e486ef2ab4a9a08c9c2c1531422cfe0123e55023fb1b157effc" "sha256": "787971d93a72d315fb906991a877356e209592be55f6f0fa79f09bc68e93848b"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -32,6 +32,14 @@
"index": "pypi", "index": "pypi",
"version": "==3.1.2" "version": "==3.1.2"
}, },
"django-extensions": {
"hashes": [
"sha256:6809c89ca952f0e08d4e0766bc0101dfaf508d7649aced1180c091d737046ea7",
"sha256:dc663652ac9460fd06580a973576820430c6d428720e874ae46b041fa63e0efa"
],
"index": "pypi",
"version": "==3.0.9"
},
"psycopg2-binary": { "psycopg2-binary": {
"hashes": [ "hashes": [
"sha256:0deac2af1a587ae12836aa07970f5cb91964f05a7c6cdb69d8425ff4c15d4e2c", "sha256:0deac2af1a587ae12836aa07970f5cb91964f05a7c6cdb69d8425ff4c15d4e2c",

@ -1,3 +1,5 @@
from django.contrib import admin from django.contrib import admin
from .models import Contact
# Register your models here. # Register your models here.
admin.site.register(Contact)

@ -0,0 +1,7 @@
from django import forms
from .models import Contact
class ContactForm(forms.modelForm):
class Meta:
model = Contact
fields = ('name', 'age',)

@ -0,0 +1,3 @@
body {
font-family: Arial, Helvetica, sans-serif;
}

@ -0,0 +1,15 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contacts</title>
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
</head>
<body>
<h1>Phonebook</h1>
<!-- where all other content will go when this template is extended to other files -->
{% block content %} {% endblock %}
</body>
</html>

@ -0,0 +1,6 @@
<!-- including the base.html as a boilerplate -->
{% extends 'contacts/base.html' %} {% block content %}
<!-- contact detail content -->
<h2>{{ contact.name }} <a href="">(edit)</a></h2>
<h4>Age: {{ contact.age }}</h4>
{% endblock %}

@ -0,0 +1,12 @@
<!-- including the base.html as a boilerplate -->
{% extends 'contacts/base.html' %} {% block content %}
<!-- contact list content -->
<h2>Contacts <a href="">(+)</a></h2>
<ul>
{% for contact in contacts %}
<li>
<a href="{% url 'contact_detail' pk=contact.pk %}">{{ contact.name }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.contact_list, name='contact_list'),
path('contacts/<int:pk>', views.contact_detail, name='contact_detail'),
]

@ -1,3 +1,15 @@
from django.shortcuts import render from django.shortcuts import render
from .models import Contact
# Create your views here. # Create your views here.
## index
def contact_list(request):
contacts = Contact.objects.all()
return render(request, 'contacts/contact_list.html', { 'contacts': contacts})
## show
def contact_detail(request, pk):
contact = Contact.objects.get(id=pk)
return render(request, 'contacts/contact_detail.html', {'contact': contact})

@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django_extensions',
'contacts' 'contacts'
] ]

@ -13,9 +13,11 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.conf.urls import include
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', include('contacts.urls')),
] ]

Loading…
Cancel
Save