Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

week 3 homework #108

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
127 changes: 127 additions & 0 deletions 4.1练习作业提交/miaozaiye/class4hm/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""
Django settings for class4hm project.

Generated by 'django-admin startproject' using Django 1.9.1.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'in5!=8d6-8do!6joheqciepe62r$+tg&w=$)j-=kws!_02_+@l'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'purelayoutblog',
]

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'class4hm.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'class4hm.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR,"static"),)

from mongoengine import connect
connect('ganji',host='127.0.0.1',port = 27017)
23 changes: 23 additions & 0 deletions 4.1练习作业提交/miaozaiye/class4hm/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""class4hm URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from purelayoutblog.views import index

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^index/',index),
]
16 changes: 16 additions & 0 deletions 4.1练习作业提交/miaozaiye/class4hm/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for class4hm project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "class4hm.settings")

application = get_wsgi_application()
Binary file added 4.1练习作业提交/miaozaiye/db.sqlite3
Binary file not shown.
10 changes: 10 additions & 0 deletions 4.1练习作业提交/miaozaiye/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "class4hm.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
Empty file.
3 changes: 3 additions & 0 deletions 4.1练习作业提交/miaozaiye/purelayoutblog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions 4.1练习作业提交/miaozaiye/purelayoutblog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class PurelayoutblogConfig(AppConfig):
name = 'purelayoutblog'
Empty file.
27 changes: 27 additions & 0 deletions 4.1练习作业提交/miaozaiye/purelayoutblog/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django.db import models
from mongoengine import *
from mongoengine import connect
import pymongo
# client = pymongo.MongoClient('localhost',27017)
#
# ganji = client['ganji']
# item_info1 = ganji['item_info1']

connect('ganji',host='127.0.0.1',port=27017)

class ItemInfo(Document):
title = StringField()
area = StringField()
url = StringField()
look = StringField()
price = StringField()
cates = StringField()
pub_date = StringField()

meta={'collection':'item_info1'}

# for i in ItemInfo.objects:
# print(i.title,i.area,i.url,i.look)

# Create your models here.

3 changes: 3 additions & 0 deletions 4.1练习作业提交/miaozaiye/purelayoutblog/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
33 changes: 33 additions & 0 deletions 4.1练习作业提交/miaozaiye/purelayoutblog/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.shortcuts import render
from purelayoutblog.models import ItemInfo
from django.core.paginator import Paginator

# Create your views here.

def index(request):
limit = 10
item_info = ItemInfo.objects[:20]
paginator = Paginator(item_info,limit)
page = request.GET.get('page',1)
print(request)
print(request.GET)


loaded = paginator.page(page)


context = {
# 'title':item_info[0].title,
# 'area' :item_info[0].area
# 'area' :'海淀区',
# 'title' :'测试一下'
'ItemInfo':loaded


}

# print (context)


return render(request,'index.html',context)

138 changes: 138 additions & 0 deletions 4.1练习作业提交/miaozaiye/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@

{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="A layout example that shows off a blog page with a list of posts.">

<title>Blog &ndash; Layout Examples &ndash; Pure</title>




<link rel="stylesheet" href="{% static "css/layouts/blog.css"%}">



<!--[if lte IE 8]>

<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/grids-responsive-old-ie-min.css">

<![endif]-->
<!--[if gt IE 8]><!-->

<link rel="stylesheet" href={% static "css/layouts/blog.css"%}>

<!--<![endif]-->






<!--[if lte IE 8]><!-->
<link rel="stylesheet" href="{% static "css/layouts/blog.css"%}">
<![endif]-->
<!--[if gt IE 8]><!-->
<link rel="stylesheet" href="{% static "css/layouts/blog.css"%}">
<!--<![endif]-->







</head>
<body>







<div id="layout" class="pure-g">
<div class="sidebar pure-u-1 pure-u-md-1-4">
<div class="header">
<h1 class="brand-title">赶集二手资料</h1>
<h2 class="brand-tagline">Python 爬虫练习作业</h2>

<nav class="nav">
<ul class="nav-list">
<li class="nav-item">
<a class="pure-button" href="http://purecss.io">Pure</a>
</li>
<li class="nav-item">
<a class="pure-button" href="http://yuilibrary.com">YUI Library</a>
</li>
</ul>
</nav>
</div>
</div>

<div class="content pure-u-1 pure-u-md-3-4">
<div>
<!-- A wrapper for all the blog posts -->

<div class="posts">
<h1 class="content-subhead">Pinned Post</h1>

<!-- A single blog post -->

{% for item in ItemInfo %}
<section class="post">
<header class="post-header">
<img class="post-avatar" alt="Tilo Mitra&#x27;s avatar" height="48" width="48" src="{% static 'img/common/tilo-avatar.png' %}">

<h2 class="post-title"><a href="{{ item.url }}">{{ item.title }}</a></h2>

<p class="post-meta">
in <a href="#" class="post-author">{{ item.area }}</a> under <a class="post-category post-category-design" href="#">CSS</a> <a class="post-category post-category-pure" href="#">Pure</a>
</p>
</header>

<div class="post-description">
<p>
发布时间:{{ item.pub_date }},
发布价格:{{ item.price }}元
</p>
</div>
</section>
{% endfor %}

<div>
{% if ItemInfo.has_previous %}
<a href = "?page={{ ItemInfo.previous_page_number }}" class="pure-menu-link">< pre </a>
{% endif %}
<span> {{ ItemInfo.number }} of {{ ItemInfo.paginator.num_pages }} </span>
{% if ItemInfo.has_next %}
<a href="?page={{ ItemInfo.next_page_number }}" class="pure-menu-link"> next> </a>
{% endif %}
</div>
</div>



<div class="footer">
<div class="pure-menu pure-menu-horizontal">
<ul>
<li class="pure-menu-item"><a href="http://purecss.io/" class="pure-menu-link">About</a></li>
<li class="pure-menu-item"><a href="http://twitter.com/yuilibrary/" class="pure-menu-link">Twitter</a></li>
<li class="pure-menu-item"><a href="http://github.com/yahoo/pure/" class="pure-menu-link">GitHub</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>






</body>
</html>
Loading