Django installation configuration (for MAC)

Source: Internet
Author: User

1. Download Django: Https://www.djangoproject.com/download

2, decompression django-1.xx.yy.tar.gz, into the Extract directory execution command

sudo python setup.py install

3. See if the installation is successful

django-admin.py --version

4. Create a project

django-admin.py startproject HelloWorld

5. Run Django

    • 1$cd HelloWorld # 切换到我们创建的项目
    • 2$ python manage.py runserver #启动服务器

6. Create an application

$ cd HelloWorld # 切换到我们创建的项目$ django-admin.py startapp hello

7. Revise the Installed_apps of settings.py in the project

INSTALLED_APPS = [    ‘django.contrib.admin‘,    ‘django.contrib.auth‘,    ‘django.contrib.contenttypes‘,    ‘django.contrib.sessions‘,    ‘django.contrib.messages‘, ‘django.contrib.staticfiles‘, ‘hello‘]

8. Create a templates in Hello to store the template file

9. Write the corresponding code in views.py in Hello

# coding:utf-8from django.http import HttpResponsefrom django.template import loader,Contextdef index(request): t = loader.get_template("index.html") c = Context({"title": "djangon"}) return HttpResponse(t.render(c))

10, Configuration engineering HelloWorld, modify urls.py as follows:

from django.conf.urls import urlfrom django.contrib import adminfrom hello import views as learn_viewsurlpatterns = [ url(r‘^$‘, learn_views.index), # new url(r‘^admin/‘, admin.site.urls),]

11, the operation of the project:

$ python manage.py runserver

12. viewing in the browser

http://127.0.0.1:8000/

Django installation configuration (for MAC)

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.