Lessons learned from 10 years of programming

0
My journey as a web developer started back in 2000 right at the age of 21 and I can clearly remember a certain characteristic of those days in terms of how they made me feel. The best term I could find to describe that feeling is… joy. I didn’t worry about things like time, deadlines or priorities or even productivity. The one thing I was concerned with was learning, as muc ...

根据ip地址定位地理位置之Python版

0
首先注册一个ip138账号并登陆,获得Token。然后进入IP查询—文档—代码示例页面,找到“Python调用iP查询接口示例”,获得代码: #!/usr/bin/python # -*- coding: utf-8 -*- #python3 import httplib2, urllib params = urllib.urlencode({'ip':'9.8.8.8','datatype':'jsonp','callback':'find'}) url = 'http://api.ip138.com/query/?'+params headers = {"token":"8594766483a2d65d ...

ValueError: Invalid format string

0
今天 在执行下面这段代码的时候, #!/usr/bin/env python # # ______ _ _ ______ _ ______ _ #(_____ | | | | (______) | | / _____) | # _____) )__ _ _ _ _____ ____ _____ __| | | |__ _ _ _ _ _____ ____| | _ ( (___ ...

Python解析json文件的方法

0
首先,json的格式: www.tuling123.com/openapi/api?key=$api_key&info=$req_info import json import requests import urllib import urllib2 KEY = '***********************' # change to your API KEY url = 'http://www.tuling123.com/openapi/api' req_info = u'讲个笑话'.encode('utf-8') query = {'key': KEY, 'info': req_info} headers = {'Content-type': 'text/html', 'charset': 'ut ...

Django 教程之五:动态URL

0
到上一教程为止,我们已经建立好一个博客的框架,但是只有一个主页,我们在网络上看到的博客,一般首页是一个文章页表,并显示文章的部分内容,点击文章标题就会跳转到文章详细页面。下面我们就来实现这一功能。 现在修改my_blog/article/views.py代码,在文件中添加如下的代码: from django.http import Http404 def detail(request, id): try: post = Article.objects.get(id=str( ...

Django 教程之四:创建模板

0
1、建立第一个模板 在template文件夹下增加base.html, 并在其中增加如下代码 <!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 blo ...

Django 教程之三:模板的工作机制

0
一、了解Django程序的逻辑 1、先来说说我们上网时,网页是如何呈现在我们屏幕上的: 通过浏览器向服务器发出request请求->从服务器获取数据->服务器处理数据->把网页呈现出来。 Django中的url设置相当于客户端向服务器发出request请求的入口, 并用来指明要调用的程序逻辑 Django中的views用来处理程序逻辑, 然后呈现到template(一般为GET方法, POST方法略有不同) Django中的template一般为html+C ...

Django 教程之二:数据库、后台

0
一、创建models 打开my_blog/article/models.py文件,将下面的代码添加到文件的末尾: class Article(models.Model) : title = models.CharField(max_length = 100) #博客题目 category = models.CharField(max_length = 50, blank = True) #博客标签 date_time = models.DateTimeField(auto_now_add = True) #博客日期 content = models.TextField(blank = True, null = True) ...

Django 教程之一:创建网站项目

0
本文的的缘起来自于本人参加实验楼的Django 搭建简易博客课程,跟着上面的课程一步一步地操作,的确是一个很好的学习编程方法。但是也有不足的地方,一是上面的Django课程使用的操作环境是Mac,大部分人都不熟悉;二是免费用户不能保存实验进度,实验没有一次做完的话,下次又要重头开始,很不方便。所以我就想在自己的电脑上建立django的环境,然后依照实验楼的教程进行学习,这样就方便很多。同时为了以 ...

Python __init__ 用法

0
学习Python的过程中,__init__ 的用法是一个难点,即使许多Python的书籍上,关于Python __init__ 用法也是写得十分拗口、难懂,今天终于找到一个关于Python __init__ 用法说明,我觉得说得很透彻,分享给大家。 一、不用__init__方法也是可以的。 比如,定义一个矩形的类,目的是求周长和面积。 class Rectangle(): def getPeri(self,a,b): return (a + b)*2 def getArea(self,a,b): ...
Page: 113 of 197 1 ... 111 112 113 114 115 ... 197