安装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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章