Intern Django [1]

Source: Internet
Author: User
Tags install django

Although the semester has not ended and the summer vacation has not yet arrived, many junior students have started internships or internships like me for a while. I only interviewed the R & D department of a data mining company and it was successful.

After I came here for my internship, due to network reasons, I did not brush questions or write a BLOG yesterday. Everything was being prepared. It was very difficult for me to do the project that the company wanted us to do, I can't say anything about it. It's probably about dealing with big data and python. Our Technical Staff let us learn about Django, so we have this series of articles. This is the first one.

I don't have to worry about writing an unofficial blog because I don't have to worry about it.

On the first day, because I want to build my environment (flushed to fedora20, configure the shell script I wrote earlier, alias, and vim, and state a lot of things such as python ), so the work time is very short. Today's task is very simple: Django concept + build Django Environment + Hello World !)

What is Django?

You cannot and don't want to be too official. Otherwise, many new users like me will turn off this boring blog.

We simply understand that, if Web development is to draw a straight line, Django is a ruler. (Django is the Web development framework, and the framework is the so-called "ruler". You can get it by yourself)

Build a Django Environment

First of all, if you are a Windows user, we can see that the author is actually a linux brain fan, and leave without any help.

The environment has been changing this semester. Previously, centos was used in the lab, ubuntu was used, and fedora 20 was used in the company.

Step 1: Make sure you have python, and mine is 2.7. If you don't have python, it's really strange and sudo yum install python on your own!

Step 2: sudo yum install django

Step 3: Find Your django/bin folder. My computer path is/usr/lib/python2.7/site-packages/django/bin, and copy it to your bin,

Sudo cp/usr/lib/python2.7/site-packages/django/bin/django-admin.py ~ /Bin /.

The preliminary work is complete.

HelloWorld

I keep thinking that the first sentence Brian Kernighan taught his children is not like 'Dad, Ms','Hello! World! '!!!!

Traditionally, HelloWorld is much more difficult than C ++. (In fact, the author may be too stupid)

First, we need to create a project. We create a folder Workspace in a folder that others have access to. After Entering Worksapce, enter the command

Django-admin.py startproject mysite (if you can't find the command, refer to step 3 of building the environment)

Then, under normal circumstances, the mysite will appear, and then the manage. py mysite (or mysite folder) will appear again.

Then we enter mysite calmly and find that there are many things including _ init _. py, settings. py, urls. py, wsgi. py !! However, currently, we only need to use urls. py.

In mysite (which has _ init _. py or something !) Create an views. py

Introduce HttpResponse and write a very simple hello Function

#!/usr/bin/env python# coding=utf-8from django.http import HttpResponsedef hello(request):    return HttpResponse("Hello World!")


Save and exit, modify urls. py

It is found that:

from django.conf.urls import patterns, include, urlfrom django.contrib import adminadmin.autodiscover()urlpatterns = patterns('',    # Examples:    # url(r'^$', 'hellow.views.home', name='home'),        # url(r'^blog/', include('blog.urls')),    url(r'^admin/', include(admin.site.urls)),     )
Let's make some modifications:

1. introduce our hello function.


2. modify patterns

from django.conf.urls import patterns, include, urlfrom django.contrib import admin  from views import hello   #Here!!!admin.autodiscover()urlpatterns = patterns('',    # Examples:    # url(r'^$', 'hellow.views.home', name='home'),        # url(r'^blog/', include('blog.urls')),    #url(r'^admin/', include(admin.site.urls)),     (r'^helloworld/',hello)   #Here!!!)
If you cannot understand such a simple regular expression, please search for it yourself ..

Come here, justOKNow

Please! Return to the directory with manage. py and enter the command

Python manage. py runserver

Very long command ~ We recommend that you create an alias account! If you don't know what alias is, use windows!

Okay, come here, please input in your browser

Http: // 127.0.0.1: 8000/helloworld/

Hello World!

Here, this article is over. I didn't expect you to stick to it. I would like to give you a thumbs up.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.