2013年9月29日星期日

Get the Cube root of a Number


;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-advanced-reader.ss" "lang")((modname e18) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ())))
(define (div-three x)
  (/ x 3.0))

;;(div-three 1 3)

(define (three-times x)
  (* x x x))

;;(three-times 2)

(define (square x)
  (* x x)
  )

;;(square 2)

(define (make-nums guess x)
  (+ (+ guess guess) (/ x (square guess))))
 
;;(make-nums 2 8)

(define (improve guess x)
  (div-three (make-nums guess x))
  )

;;(improve 2 8)

(define (good-enough? guess x)
  (< (abs (- (three-times guess) x)) 0.001))

;;(good-enough? 2 8)

(define (cube-root-iter guess x )
  (if (good-enough? guess x)
      guess
      (cube-root-iter (improve guess x) x)))

;;(cube-root-iter 2 8)

(define (cube-root x)
  (cube-root-iter 1.0 x))

(cube-root 27)

2013年9月28日星期六

Crusher Django Tutorial(6) Load Static Files In Django

Cute and hate ADs: A website I made for sale py-cone-crusher(For god sake help me click it or just ignore it.55555555)

Welcome to the sixth Django Tutorial -- how to load css file and pic file in Django.It is easy in html or php,but in Django we have to do some job but it not very hard.

First,we need to new a folder named static, and with it we use the css frame-work BootStrap which is awesome!

Then, we edit the urls.py:

 
#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.conf.urls.defaults import *
from hello.TomAndJerry.views import *  # import all the funtions, we have only one

import os   # import os

from django.contrib import admin   # import admin
admin.autodiscover()               # add this to make admin discover

static = os.path.join(os.path.dirname(__file__), 'static')

urlpatterns = patterns('',
    (r'^$', show),  # conf the function
    (r'^just_show/$', just_show),
    (r'^info/(.+)/', info),
    (r'^info/$', info),
    (r'^admin/', include(admin.site.urls)), # add this line to conf admin page url
    (r'^static/(?P<path>.*)$', 'django.views.static.serve',
    { 'document_root': static }),      # conf the static root
)
 

The last step is add the link tag in the TomAndJerry.html template file:

 
<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" href="/static/bootstarp.css" type="text/css" media="screen" title="no title" charset="utf-8" />
        <link rel="stylesheet" href="/static/bootstrap-responsive.css" type="text/css" media="screen" title="no title" charset="utf-8" />
        <title>Tom And Jerry</title>
        
    </head>
    <body>
        <h1>Tom And Jerry Show</h1>
        <p>
            Tom And Jerry is a carton show which is Cool, I know this is sounds
            silly...
        </p>
        <h2>{{ title }}</h2>
        <ul>
        {% for player in players %}
            <li>{{ player }} is a player.</li>
        {% endfor %}
        </ul>
        {% if same %}
            <p>
                No one win...
            </p>
            <img src="/static/black.png" alt="black png file" title="black png file" width="156" height="155" />
        {% else %}
            <p>
                Tom Win the game!
            </p>
             <img src="/static/hello.png" alt="hello django png" title="this is a png file" width="170" height="167" />
        {% endif %}
    </body>
</html>
 

As you can see, we load the css file from the static folder and remove the css code in the html which will make our code more clean. And we load the img by the player who win.That is also not hard to understand. Let's just test our result:

BTW, the bootstrap-responsive.css is for the Responsive Web Design which is cool!

Well, that is what we learn today,in the next post we will learn the Form in Djang.

2013年9月26日星期四

The Strong Impact Crusher From SBM Is The Best Crusher

The Strong Impact Crusher From SBM


The PF Impact Crusher involve the use of impact rather than pressure to crush material. The material is contained within a cage, with openings on the bottom, end, or side of the desired size to allow pulverized material to escape. There are two types of impact crushers: horizontal shaft impactor and vertical shaft impactor.It Usually acting in the secondary or three-stage crushing equipment, Impact crusher is the ideal crusher for aggregates processing in high-type high-type highway building, water conservancy and power construction. For crushing materials whose compressive strength is under 360Mpa, and particle size is under 500mm, impact crusher with end products in cubic shape is better than cone crusher and hammer crusher.

Mramor ima primjenu u kiparstvu i arhitekturi, lako se reže, obrađuje i polira. U likovnoj umjetnosti je cijenjen zbog svoje mliječne boje, poluprozirnosti i toplote koja podsjeća na ljudski dodir. U V stoljeću p.n.e. stanovnici ostrva Kios su u Delfima, ispred Apolonovog hrama sagradili oltar od crnog mramora. Restauriran je 1920. godine. U antici najznačajnije građevine i skulpture nastale su od čuvenog mramora s otoka Para (grčki: Parosa) i brda Pentelikona. U Italiji je cijenjen mramor iz Carrare od kojeg je izrađen i Mikelanđelov David. Mramor sa ostrva Brač je cijenjen u cijelom svijetu pa su mnoge građevine izgrađene upravo od tog kamena (od Dioklecijanove palače, Meštrovićevog Indijanca u Chikagu do stubova Bijele kuće u Washingtonu).

Impact Crusher Spare Parts Easy To Replace, A Corresponding Reduction In Maintenance Costs

The impact crusher rotor installed only six plate hammer, with a special tool designed Huacheng Heavy can easily board hammer replacement, replacement of a board hammer just a shift of the time. The bottom of the grinding chamber grinding rod replacement also requires only tens of minutes, greatly reducing the overhaul and maintenance time and costs.

cone crusher plant

2013年9月25日星期三

Crusher Django Tutorial(5) Using The Admin System

Cute and hate ADs: A website I made for sale impact-crusher(For god sake help me click it or just ignore it.55555555)

In the previous post,we learn the basic things about the Model,and we created an easy App -- TomAndJerry,in this tutorial we will continue the tutorial and use the Admin System in our TomAndJerry App,so let move on to the basic Admin System to manage our data -- the roles in the show.

First, we have to conf the url of admin:

 
#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.conf.urls.defaults import *
from hello.TomAndJerry.views import *  # import all the funtions, we have only one

from django.contrib import admin   # import admin
admin.autodiscover()               # add this to make admin discover

urlpatterns = patterns('',
    (r'^$', show),  # conf the function
    (r'^just_show/$', just_show),
    (r'^info/(.+)/', info),
    (r'^info/$', info),
    (r'^admin/', include(admin.site.urls)), # add this line to conf admin page url
)
 

Then, edit the settings.py to tell Django we have the App of Admin:

 
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'hello.TomAndJerry',
    'django.contrib.admin', # Add the Admin App
)
 

Now, we have to use the python manage.py syncdb command to create the admin log otherwise we can not log in the admin page:

 
zoo@ubuntu:~/hello$ python manage.py syncdb
Creating table django_admin_log
Installing index for admin.LogEntry model
 

The command of python manage.py syncdb means that when we have anything new in the database we have to re-type it so that our table in database will re-new the model we created.

And now, we new a new python file in the folder TomAndJerry called admin.py which is the views of the admin page, when we log in the admin system, we can contorl the data with the player model:

 
#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.contrib import admin
from hello.TomAndJerry.models import player

admin.site.register(player) # registe the player class 
 

Now, we re-start the Django server and just test our admin System:

Just add a new player named Fat-Dog who is 9 years old.

Now,we have 3 players in our database,just check the just_show page see if it change:

Great, our job works,that is our basic things about the admin system in Django, and next post we will learn how to use the static file like css, javascript and images in Django. You must don't want to miss it. Welcome to feedback.

2013年9月24日星期二

Crusher Django Tutorial(4) Using Basic Model

Cute and hate ADs: A website I made for sale impact-crusher(For god sake help me click it or just ignore it.55555555)

In the previous post,we learn the basic Template System in Django. And that is just for the static page,at least the data we pass from views.py is in the memory of the computer,not in the database, that means when we shut down the server or we shut down the computer,the data gone.If we use the database, we can store it in the local disk, that can be used when we load it,but not re-create it from the memory. In order to create the "temporary" permanent data(nothing is permanent...), we need to play with Model in Django.So let's move on!

With Django, we can use many database products,like Mysql,Sqlite,Oracle,but we will use the smallest DB -- Sqlite3 to learn the Model.In fact,in the small case of webpage, we don't need to use the strong DB like Oracle even Mysql.We have ORM, right? I think the ORM is great, because I am an idiot for SQL...

So,before we create the models today, we should do something to conf the database,include the: name of database(sqlite3), the local file(a file ends with ".db"),we don't need other info using the sqlite3, if you use other database you should fill the fields in the following code in the settings.py(remember her?):


DATABASE_ENGINE = ''
DATABASE_NAME = ''
DATABASE_USER = ''
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''

Well, I will continue the previous post -- TomAndJerry Show App, and if you miss it, you can just read it back.Besides, we will use the url conf so that we can make it all we have learned used in our App.First, we conf the databse:

After conf the database, we should create the role model in our App-- TomAndJerry, in the class -- Player we give every role has three fields: name,age,role in the Cartoon. Edit the models.py in the folder TomAndJerry like this:

 
DATABASE_ENGINE = 'sqlite3'           
DATABASE_NAME = './data.db'            
DATABASE_USER = ''             
DATABASE_PASSWORD = ''         
DATABASE_HOST = ''              
DATABASE_PORT = ''
 

That is our conf about the database we used.Just give the name and the local file of the database.

 
#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.db import models

class player(models.Model):
    name = models.CharField(max_length = 30)
    age = models.IntegerField()
    role = models.CharField(max_length = 40)
    
    # re-define the unicode function
    def __unicode__(self):
        return u'%s is a(an) %s,he is %s years old' % (self.name,self.role,self.age)
    
    class Meta:
        ordering = ['age']
 

So,we have created our player class, the __unicode__() is the way we show an object of the player class, the Meta class is a Meta Class which inclueds the ording rule -- age.

After created the player model,we need to see the real SQL code and check it if anything wrong in it, just using the command python manage.py sqlall TomAndJerry and python manage.py validate:

 
zoo@ubuntu:~/hello$ python manage.py sqlall TomAndJerry
BEGIN;
CREATE TABLE "TomAndJerry_player" (
    "id" integer NOT NULL PRIMARY KEY,
    "name" varchar(30) NOT NULL,
    "age" integer NOT NULL,
    "role" varchar(40) NOT NULL
)
;
COMMIT;
 
 
zoo@ubuntu:~/hello$ python manage.py validate
0 errors found
 

We see that it will give the SQL code for our model.Now, we need to install it to our App,that means create the Table in the SQL code:

 
zoo@ubuntu:~/hello$ python manage.py validate
0 errors found
zoo@ubuntu:~/hello$ python manage.py syncdb
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table TomAndJerry_player

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'zoo'): zoo
E-mail address: aswe@gmail.com
Password: 
Password (again): 
Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model
 

In this step,we see that the table TomAndJerry_player has been created,besides, we also created a admin user(That's the next post will talked about) for our website just do as Django tell us is ok.If everything is ok,we will see a local database data.db has been created which means our job is ok for now.

Now,we have the database and the table,but there is nothing in it.So we have to insert something into table.Just using the python manage.py shell in the website root folder.

 
Python 2.6.5 (r265:79063, Oct  1 2012, 22:07:21) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from TomAndJerry.models import player       # import the class
>>> Tom = player(name="Tom",age=5,role="mouse") # create a object but not insert into table
>>> Tom                                         # show it
 
>>> Tom.save()                                  # save means insert into tabel
>>> player.objects.all()                        # get all data
[]
>>> Jerry = player(name="Jerry",age=6,role="cat")
>>> Jerry

>>> player.objects.all()                        # before save Jerry
[]
>>> Jerry.save()                                # saved Jerry
>>> player.objects.all()
[, ]
>>> from sys import exit
>>> exit(0)
 

Now,we get two roles in our table player. The next job is show them in our page.For easy way, we just create another template named show.html in the folder templates.

 
<html>
<head>
 <title>Show The Players</title>
</head>
<body>
 <h1>The Cartoon Show</h1>
 <h2>The role in the Cartoon:</h2>
 <ol>
  {% for role in roles %}
   <li>{{ role }}</li>
  {% endfor %}
 </ol>
</body>
</html>
 

The tempalte html has nothing new for now. But we have to create a new function named just_show() in the views.py:

 
#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.shortcuts import render_to_response
from hello.TomAndJerry.models import player   # don't forget import the class

import random

def show(request):
    title = "The roles in the show:"
    players = ["Tom","Jerry","Fat dog"]
    tom_number = int(random.random()*10)
    jerry_number = int(random.random()*10)
    if tom_number == jerry_number:
        same = True
    else:
        same = False
    return render_to_response("TomAndJerry.html", locals())

def just_show(request):
    roles = player.objects.all()
    return render_to_response("show.html", locals())
 

And we need to conf the urls.py(Oh, so much work to do and so few time...)

 
from django.conf.urls.defaults import *
from hello.TomAndJerry.views import *  # import all the funtions, we have only one

urlpatterns = patterns('',
    (r'^$', show),  # conf the function
    (r'^just_show/$', just_show),
)
 

Now, we can just test our job:

Yoo,it works.So,that is just what we have learn today.But we can put the all things we have learn.Extends the url to show the everyone's info.If we input Tom,we show Tom's info, we input Jerry, we show Jerry's info,we input a name not in our database, we raise 404 error,ok,just start it.

Create html file named info.html as this:

 
<html>
<head>
 <title>Info For Player</title>
</head>
<body>
 {% if role %}
  <h1>{{ role.name }} is A(an) {{ role.role }}, and he is {{ role.age }} years old.</h1>
 {% else %}
  <h1>Error</h1>
 {% endif %}
</body>
</html>
 

And then we create a function in views.py named info:

 
#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.http import Http404, HttpResponse
from django.shortcuts import render_to_response
from hello.TomAndJerry.models import player   # don't forget import the class

import random

def show(request):
    title = "The roles in the show:"
    players = ["Tom","Jerry","Fat dog"]
    tom_number = int(random.random()*10)
    jerry_number = int(random.random()*10)
    if tom_number == jerry_number:
        same = True
    else:
        same = False
    return render_to_response("TomAndJerry.html", locals())

def just_show(request):
    roles = player.objects.all()
    return render_to_response("show.html", locals())


def info(request,name = None):
    if name is None:  # Nothing input return the error info
        return HttpResponse("nothing input")
    try:
        role = player.objects.get(name=name)
        return render_to_response("info.html", locals())
    except Exception:
        raise Http404()
 

And don't forget the urls.py:

 
from django.conf.urls.defaults import *
from hello.TomAndJerry.views import *  # import all the funtions, we have only one

urlpatterns = patterns('',
    (r'^$', show),  # conf the function
    (r'^just_show/$', just_show),
    (r'^info/(.+)/', info),
    (r'^info/$', info),
)
 

Now,we test our job we did:

Great! Everything is ok. Well, you may think that when we input the things into the table using the command line is too silly.That's ture,we will learn the how to use admin page next post.Don't miss it and welcome feedback~!

2013年9月23日星期一

Crusher Django Tutorial(3) Using Template

Cute and hate ADs: A website I made for sale impact-crusher(For god sake help me click it or just ignore it.55555555)

In the previous post,we learn the basic url conf in Django,I am appreciative that @Will Farley and @Nathan Cox,they told me that the Virtualenv and pip,I google them,I still don't know the advantages of them.If you want you can see here about the pip,that helpful for your site-packets manage.BTW,if you know the advantages of pip,maybe you can tell me.

In fact you can just using the following command to install with network,of course:


zoo@ubuntu:~/Desktop$ sudo apt-get install python-virtualenv

zoo@ubuntu:~/Desktop$ sudo pip install django

Well, in this tutorial, we will learn the Templates System in Django. Now,we need start An App first, and then using the App for the real job,but not just have a fun with Django. First,we can forget the views.py,and start an app with the command in our hello project:


zoo@ubuntu:~/hello$ python manage.py startapp TomAndJerry

Using App can make the manage easy and make your project more logical,here we create a TomAndJerry project.You can see that there are four files

  • The __init__.py will make the TomAndJerry as a packet.
  • The test.py, I don't know maybe just unit test of the App.
  • The models.py, that is the class we designed in MTV(model,templates,view).
  • The views.py that we know, the function we create function to control the Logic.

After create our App,we need to tell the settings.py that we have create it (I wonder why the Django can not add it...), just edit the settings.py:


INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'hello.TomAndJerry',  # Add this line to conf the App we create just now
)

Em,now we need A Templates Directory to hold our templates, in the project directory create a folder named templates,and create a html file -- TomAndJerry.html the code looks this:


<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <title>Tom And Jerry</title>
        <style type="text/css" media="screen">
            h1 {
                color: gray;   
            }
            p {
                font-size: 14px;
            }
            ul {
                list-style:none;
            }
        </style>
    </head>
    <body>
        <h1>Tom And Jerry Show</h1>
        <p>
            Tom And Jerry is a carton show which is Cool, I know this is sounds
            silly...
        </p>
        <h2>{{ title }}</h2>
        <ul>
        {% for player in players %}
            <li>{{ player }} is a player.</li>
        {% endfor %}
        </ul>
        {% if tom_is_power %}
            <p>
                Tom win the game!
            </p>
        {% else %}
            <p>
                Jerry win the game!
            </p>
        {% endif %}
    </body>
</html>


And then,we have to tell the settings.py: we make a templates, when I want it, you have to give me work it out! Don't forget to use absolute paths, not relative paths.


TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    "/home/zoo/hello/templates",
)

When you look at the html code which is a bit different from the html we ever seen before,we got the double quotes and the code if the {% %}, that is the dynamic variables we will pass to the template file in the views.py file.In this way, the content we generated will currently passed to the template.

Add, you may want to know, why we don't make the Css Style out,and link it from a external file like style.css.That is we should conf it later,don't be worry, I won't forget it.

For now,we can create our functions in the App views.py:



#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.shortcuts import render_to_response

def show(request):
    title = "The roles in the show:"
    players = ["Tom","Jerry","Fat dog"]
    tom_is_power = True
    return render_to_response("TomAndJerry.html", locals())

Well,don't forget the url we going to conf:


from django.conf.urls.defaults import *
from hello.TomAndJerry.views import *  # import all the funtions, we have only one

urlpatterns = patterns('',
    (r'^$', show),  # conf the function
)

Now, we almost done about the basic page. Just check out the job,just start the server:


zoo@ubuntu:~/Desktop$ python manage.py runserver 0.0.0.0:8000

Good!It works!Haha...but for the code, I use a hack to save time, the locals() function is all the vars in the context(includes the request). Just try it:


zoo@ubuntu:~/桌面/T3$ python
Python 2.6.5 (r265:79063, Oct  1 2012, 22:07:21) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> locals()
{'__builtins__': , '__name__': '__main__', '__doc__': None, '__package__': None}
>>> 

So, that is our basic things about the Templates System.Now,we can do something fun to see Tom and Jerry who is win by the two numbers generated by the computer using rand() function.If the number are the same,no one win,else Tom win(Tom always win) Nothing new,just for fun.

Change the template html file:


<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <title>Tom And Jerry</title>
        <style type="text/css" media="screen">
            h1 {
                color: gray;   
            }
            p {
                font-size: 14px;
            }
            ul {
                list-style:none;
            }
        </style>
    </head>
    <body>
        <h1>Tom And Jerry Show</h1>
        <p>
            Tom And Jerry is a carton show which is Cool, I know this is sounds
            silly...
        </p>
        <h2>{{ title }}</h2>
        <ul>
        {% for player in players %}
            <li>{{ player }} is a player.</li>
        {% endfor %}
        </ul>
        {% if same %}
            <p>
                No one win...
            </p>
        {% else %}
            <p>
                Tom Win the game!
            </p>
        {% endif %}
    </body>
</html>

Also, change the views.py to re-create the function:


#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.shortcuts import render_to_response
import random

def show(request):
    title = "The roles in the show:"
    players = ["Tom","Jerry","Fat dog"]
    tom_number = int(random.random()*10)
    jerry_number = int(random.random()*10)
    if tom_number == jerry_number:
        same = True
    else:
        same = False
    return render_to_response("TomAndJerry.html", locals())

Now,we can refresh the page and see the different page.Yoo! The cat will never win,poor cat...LOL...

But,there are something more about the template system, you can learn it by the django-doc.The next post we will learn the Model of the Django which is the core concept of the MVT(model,view,template). You won't want to miss!

Crusher Django Tutorial(2) conf the basic url

Cute and hate ADs: A website I made for sale impact-crusher(For god sake help me click it or just ignore it.55555555)

In the previous post,I am sorry make the code so ugly that maybe you can not understand,thanks for @Leo Trubach,he gave me a lot of tips about the code style.BTW, he think the django version 1.1.1 is too old.Well,I chang the version to the Django-1.4.8 :), and I will show you how to install django,and then we will see something real with Django, hope you will like it!

Install django, first download django from here https://www.djangoproject.com/ I use the Version of 1.4.8, you can choice the version you like.

Then, use the tar command to decompress the packet like this


zoo@ubuntu:~/django$ tar zxvf Django-1.4.8.tar.gz

get in the directory, and use "sudo python" command to install Django like this


sudo python setup.py install

After input the password and Enter, it will get out a lot of install Information when it over,we can check it ok or not:


zoo@ubuntu:~/django/Django-1.4.8$ python
Python 2.6.5 (r265:79063, Oct  1 2012, 22:07:21) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> dir(django)
['VERSION', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'get_version']
>>> django.get_version()
'1.4.8'

When you see this, that means you have installed Django Successfully.Ok, we can move on about tutorial today. In this Tutorial,we will learn the basic url conf, which is different with original PHP(means not use the frame work).

Well, let continue the previous post,Oh, forget it,let us start from the very begining.

We just start a project with the command


zoo@ubuntu:~$ django-admin startproject hello

Then, we just create a Python file named views.py to create our basic function.

And now,we will use something Dynamic in the page to show the current time of your system.just edit the views.py like this:(we will talk about it later)


#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.http import HttpResponse
import datetime

def time_now(request):
    now = datetime.datetime.now()
    html = "<html><body>It is %s now</body></html>" % now
    return HttpResponse(html)

The code above here looks like the "Hello World" we talked before, just reedit the urls.py, set the homepage in the time_now function, you will get the result:

You may think that Django is so so, I can not get anything different like PHP.I have to write the code in the HTML and then give it to Django.Here we change something to make it better.

Here is a problem to hack.I have a number in a url, And I want to judge it is an odd number or even.The number input from the URL(that sounds silly),but we just assume that.Just for learn the url conf in Django. Just edit the views.py like this:


#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.http import HttpResponse,Http404
import datetime

def time_now(request):
    now = datetime.datetime.now()
    html = "<html><body>It is %s now</body></html>" % now
    return HttpResponse(html)


def judge(reqest, number):
    try:
        number = int(number)
    except ValueError:
        raise Http404() # raise 404 error
    if number % 2 == 0:
        html = "<html><body>%d is even!</body></html>" % (number)
    else:
        html = "<html><body>%d is odd!</body></html>" % (number)
    return HttpResponse(html)

That just add a more function, but we have a more parameter,that is from the URL in fact.Now we need to conf the URL Just edit the urls.py:


from django.conf.urls.defaults import *

from views import *

urlpatterns = patterns('',
   (r'^$', time_now),
   (r'^number/(.+)$', judge), # we just want the number in the url, not more or less
)

The (.+) means more than one chars, I know it is silly, if you know something better, have to tell me!!! Now, we can test it with the url: http://0.0.0.0:8000/number/123 or http://0.0.0.0:8000/number/-123 or http://0.0.0.0:8000/number/12 and so on.

Well, at least it works, but if we input nothing just like: http://0.0.0.0:8000/number/ the program will die.How to fix it? I use the StackOverflow haha: http://stackoverflow.com/questions/18943564/django-to-conf-a-url-that-contains-a-number/18943653#18943653

just add a more line to conf, even do not have to add more function! So cool!



from django.conf.urls.defaults import *

from views import *

urlpatterns = patterns('',
   (r'^$', time_now),
   (r'^number/(.+)$', judge), # we just want the number in the url, not more or less
   (r'^number/$', judge),  # handle the empty input
)


the function is :

#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.http import HttpResponse,Http404
import datetime

def time_now(request):
    now = datetime.datetime.now()
    html = "<html><body>It is %s now</body></html>" % now
    return HttpResponse(html)


def judge(reqest, number = None):
    if number is None:
        html = "nothing input!"
        return HttpResponse(html)
    try:
        number = int(number)
    except ValueError:
        raise Http404() 
    if number % 2 == 0:
        html = "<html><body>%d is even!</body></html>" % (number)
    else:
        html = "<html><body>%d is odd!</body></html>" % (number)
    return HttpResponse(html)

That will works for our funtion! Well,Thanks for reading the second Tutorial, I am also new to Django, but I want to learn it. Just learn with me or read the book called: The Definitive Guide to django which is awesome!

2013年9月21日星期六

Crusher Django Tutorial(1) hello world


if __name __ == "__main__":
    print "jaw crusher from China!"

Cute and hate ADs: A suck website I made(For god sake help me click it or just ignore it.55555555)

Hello,everyone,I will start a Django Tutorial,and I am a big Fan of Python and Django,So, I mean I am crush into Python and Django. I using the GNU/Linux Operating System to learning the Python and Django, and I think the Windows CMD is too weak to doing the Programming. :) Let us start the tutorial with the Terminal in the Linux. Let us try hello world with the terminal.

Then we install the Django(the install is so easy , and I skip the step). First,we check out the django lib is ok in your system:


Python 2.6.5 (r265:79063, Oct 1 2012, 22:07:21)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import django
>>> dir(django)
['VERSION', '__builtins__', '__doc__', '__file__',
'__name__', '__package__', '__path__', 'get_version']
>>> django.get_version

>>> django.get_version()

Well,well,well, the django is installed in your System. Then we can just turn a directory that is English path(I am a Chinese),so maybe there is nothing not prefect with you. Here I use the root directory of my user ~ :


zoo@ubuntu:~$ django-admin startproject hello

nothing error, nothing means everything ok. And check the path, there is a folder Added named hello. All right, that is our base directory.

In the folder, there are four files

the __init__.py is a file that will make the folder as a packet as default.I do not know the more about it. LOL... the manage.py includes the all kinds of the command we can use.

The settings.py is all kinds of the setting of the project,like the database we use, the templates we set down and so on, we will talk about it later.

The url.py is all the url Configuration we use it to conf the views to the function.If you do not understand, just do it, the more you do, the more you will understand.

Ok, just start the “hello world” page! Just open the terminal and start the command:


zoo@ubuntu:~/hello$ python manage.py runserver
0.0.0.0:8000
Validating models...
0 errors found
Django version 1.1.1, using settings 'hello.settings'
Development server is running at
http://0.0.0.0:8000/
Quit the server with CONTROL-C.

the runserver means start the server, use django you won't have to use the server like Apache or Nignx,just django!BTW, the 0.0.0.0 means if you have a public IP Address, your friends not in your local network will see your page, that is real cool! Now you can open the Chrome or firefix and type the address:

http://localhost:8000

Ok, the default page you see here! Then we can just try the real hello world, but not just use the default page of django. OK. First, add the file names views.py:


#!/usr/bin/env python
#-*- coding:utf-8 -*-
from django.http import HttpResponse
def hello(request):
    return HttpResponse("""<html>
             <body>
             <h1>
              Hello Crusher
             </h1>
             </body>
             </html>""")

Then, we need to conf the url.py to make the view inflect the function: eidt the url.py like this:


#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.conf.urls.defaults import *
from views import *

urlpatterns = patterns('',
    (r'^$', hello),
)

the line of : from views import * means import the function to the current file:url.py the line : (r'^$', hello), means the bind nothing of the url to the function.That means you refresh the http://localhost:8000 you can see the webpage we created:

Now, we create the first django page, in fact we can make the page a little more complex: just add the html like this in the “”””””:


<html>

<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>Hello Django</title>
    <style type="text/css" media="screen">
    h1 {
        color: red;
    }
    li {
        color: gray;
    }
    </style>
</head>

<body>
    <h1>Hello World</h1>
    <h2>I like the following item:</h2>
    <ul>
        <li>
            Python
        </li>
        <li>
            Django
        </li>
        <li>
            Linux
        </li>
    </ul>
</body>

</html>


Ok, then we refresh the page, we can see the new page like this:

Well, that seems better than the just hello world page. Wait, the next tutorial we will see something more fun, just wait me to reblog!

2013年9月20日星期五

How to choose Suitable Crusher for Cement Production

How to choose Suitable Crusher for Cement Production

Cement is made from lime stones and clay through calcination at high temperature. In the cement production process, most of the materials need to be crushed, such as limestone, clay and mine, etc. The biggest quantity of materials is limestone, whose size is large and hardness is high after exploitation, so it is very important to crush limestone in cement production process. In cement production, most of the materials need to crusher. Limestone takes a large proportion in cement processing, and has high hardness and large particles, so it also need to be processed by crusher. Generally stone manufacturing line is: hopper-vibrating feeding machine-DPC single stage hammer crusher- screening equipment-final production.

The stone manufacturing line in every cement production plant is similar, however the final materials is stone powder, so it must add the step of grinding process in cement manufacturing plant. While crushing process is more economic and convenient than grinding process. The large-block materials should be crushed to tiny and even size as possible as they can before entering milling machine, in order to alleviate the load of milling machine and increase the output of milling. Meanwhile it can lighten the segregation phenomenon in varying degrees in transportation and storage, raising the exactitude of ingredient after materials crushed.

Cement grinding process is the key step in the cement  manufacturing line. In the cement grinding process, limestone, coal, gypsum and clinker need to be grinded into powder by cement grinding equipment. At present, most of cement production plant is mature in the technology of bag filter and electrical precipitation and all of them can reach the country’s requirement for dust emission. However, as soon as you perceive, it shows that environment has been damage seriously. Environment has a negative effect on the quality of life, healthy life and human activities.

So it is very important to choose the crushing and grinding machine, because limestone is high hardness material, and it can be crushed by DPC single stage hammer crusher, which specially used for the rigor condition of limestone abrasive, at last screened by vibrating screen. At this time materials which match the desired size go to the next step—grinding, materials which don’t meet the size go back and continue to crush, until reach the required size.

The stone crushing equipment of SBM Machinery has plenty of advantages, such as high efficiency, capital-saving, reasonable structure and reliable operating, etc. So it is ideal equipment for cement  manufacturing line. Shanghai SBM Machinery Co., Ltd has designed and manufactured a large amount of various crushers, a series of new rock-crushing equipment, which largely expands the concept domain of coarse crushing and fine crushing. It has successfully removed the obstacle that crushing site, environment and complex infrastructure. SBM Machinery has made great contributions in cement industry, and we will always on the way!

2013年9月18日星期三

Python,Crusher,XAMPP,CGI


The way to use CGI in Python and in the XAMPP under Win-7:

1.install Python and XAMPP first and add the env var of Python:






2.install XAMPP:


3.Add the mysql env var for the system:

E:\xampp\mysql\bin



4.chang the password for the root user:



5. add the following lines to the file E:\xampp\apache\conf\httpd.conf :

AddHandler cgi-script .cgi .pl .asp .py


AddType text/html .shtml .py


Options Indexes FollowSymLinks Includes ExecCGI

6.6.new a file named hello.py:
you should notice the right path of the python.exe or it will be error by Apache

#!C:\Python27\python.exe
print "Content-Type: text/html\n"
print """hello Crusher

Hello Python CGI Crusher

"""
6.test:


7. try the CGI with the Mysql and the data:

sql:





create database books;

use books;

create table book (
 id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
 name VARCHAR(255)
);

insert into book (name) values ("Django book");
insert into book (name) values ("Python Book");



8.the python code:

#!C:\Python27\python.exe

import MySQLdb

print "Content-Type: text/html\n"
print "<html><head><title>Books</title></head>"
print "<body>"
print """<h1>Books</h1>"""
print "<ul>"

connection = MySQLdb.connect(user='root', passwd='zoosuck', db='books')
cursor = connection.cursor()
cursor.execute("SELECT name from book;")

for row in cursor.fetchall():
    print "<li>%s</li>" % row[0]

print "</ul>"
print "</body></html>"

connection.close()

9.the data in the page:
Cute and hate ADs: A suck website I made(For god sake help me click it or just ignore it.55555555)








2013年9月5日星期四

10 ways to keep that back-to-work fresh start enthusiasm all week in Monday

Cute and hate ADs: A suck website I made(For god sake help me click it or just ignore it.55555555)

Feel sleepy in Monday morning and do not want to do anything but sleep?

Here I provide you some tips to avoid the situation:



  1. Don't be late for work!
  2. The first day you late,your manager must be not happy for that.He/She will thinks less of you.Remember, never be late for the first day in a week.
  3. Take a deep breath before you start job.
  4. Make sure that you can breath mercilessly!
  5. Make A Plan for the plan of this week. Always have a plan for everything.And image that you can GTD(get things down).
  6. Drink more water to keep your body and brain in good condition.
  7. Focus On the job you are doing,Even if a few minutes.That make you keep focus.
  8. Take a few walk.If you can not focus on, well, get up and take a walk.Do not stare on the screen all the time.
  9. Wash your face if you are too sleep to focus on the job you are doing.
  10. Think about you will have a big Lunch and you will have power to do anything.
  11. Think something stimulate and you will feel better!
  12. Ask for leave one day, you can sleep all day long... LOL :)

2013年9月2日星期一

make your code in the blog cool with highlight.js :)


As you see, the python code is so cool except the print content, the "hell jaw crusher"... for life , I have to Advertising for my company.555555...

if __name __ == "__main__":
    print "jaw crusher from China!"

just load the css and the js file like this:

<link href="http://yandex.st/highlightjs/7.3/styles/sunburst.min.css" rel="stylesheet"></link>
<script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

then add your code like this:








<pre><code class="python">
if __name __ == "__main__":
    print "jaw crusher from China!"
</code>
</pre>

more info you can just click:

http://www.softwaremaniacs.org/soft/highlight/en/download/ and : http://www.softwaremaniacs.org/soft/highlight/en/