安裝django的步驟:

安裝django的步驟:

1、安裝python,選擇默認安裝在c盤即可。設置環境變量path,值添加python的安裝路徑。

2、下載ez_setup.py,下載地址:http://peak.telecommunity.com/dist/ez_setup.py
    放在某個文件夾下,在cmd裏進入該文件夾,運行python ez_setup.py install

3、下載Django ,下載地址:https://www.djangoproject.com/download/
    下載後解壓,在cmd裏進入Django所在的目錄,運行python setup.py install,然後開始安裝,Django將要被安裝到Python的Lib下site-packages。

4、設置Django的環境變量,在path裏添加C:\Python33\Lib\site-packages\Django-1.7.1-py3.3.egg\django\bin

創建一個網站:

先進入要創建網站的目錄,比如我要在E:\website 裏創建一個站點,則用cmd進入該目錄,再使用django-admin.py startproject mysite 命令,如果沒有任何提示,則再打開該目錄,是否多了mysite文件夾,如果沒有出現該文件夾,則說明  .py 文件默認打開方式不是下圖第一個

隨意選中一個python文件,右鍵選擇打開方式,將其默認打開方式設置成上面第一個。在cmd裏再次運行django-admin.py startproject mysite 命令,注意這個命令是不加.pyd的。我快被各位網友給搞死了。應該是django-admin startproject mysite。。如果加了.py,就會打開django-admin.py這個程序。

網友們:下次抄別人博客的時候,能不能自己試一遍,走點心???

你會發現在E:\website 裏創建了mysite文件夾。ok,問題解決了。

補充:

  有網友也會通過另一個方法解決:換這個命令python django-admin startproject mysite,其實也就是使用python執行。這樣就不需要修改python默認打開方式

 

順便貼一下官方使用目錄https://docs.djangoproject.com/en/1.10/intro/tutorial01/#creating-the-polls-app

目前我遇到的最簡單的安裝方式:

pip install -e django/

貼一下官方使用文檔

Writing your first Django app, part 1

Let’s learn by example.

Throughout this tutorial, we’ll walk you through the creation of a basic poll application.

It’ll consist of two parts:

  • A public site that lets people view polls and vote in them.
  • An admin site that lets you add, change, and delete polls.

We’ll assume you have Django installed already. You can tell Django is installed and which version by running the following command:

$ python -m django --version

If Django is installed, you should see the version of your installation. If it isn’t, you’ll get an error telling “No module named django”.

This tutorial is written for Django 1.10 and Python 3.4 or later. If the Django version doesn’t match, you can refer to the tutorial for your version of Django by using the version switcher at the bottom right corner of this page, or update Django to the newest version. If you are still using Python 2.7, you will need to adjust the code samples slightly, as described in comments.

See How to install Django for advice on how to remove older versions of Django and install a newer one.

Where to get help:

If you’re having trouble going through this tutorial, please post a message to django-users or drop by#django on irc.freenode.net to chat with other Django users who might be able to help.

Creating a project

If this is your first time using Django, you’ll have to take care of some initial setup. Namely, you’ll need to auto-generate some code that establishes a Django project – a collection of settings for an instance of Django, including database configuration, Django-specific options and application-specific settings.

From the command line, cd into a directory where you’d like to store your code, then run the following command:

$ django-admin startproject mysite

This will create a mysite directory in your current directory. If it didn’t work, see Problems running django-admin.

Note

You’ll need to avoid naming projects after built-in Python or Django components. In particular, this means you should avoid using names like django (which will conflict with Django itself) or test (which conflicts with a built-in Python package).

Where should this code live?

If your background is in plain old PHP (with no use of modern frameworks), you’re probably used to putting code under the Web server’s document root (in a place such as /var/www). With Django, you don’t do that. It’s not a good idea to put any of this Python code within your Web server’s document root, because it risks the possibility that people may be able to view your code over the Web. That’s not good for security.

Put your code in some directory outside of the document root, such as /home/mycode.

Let’s look at what startproject created:

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章