Install django and debugging tools

Source: Internet
Author: User
Tags install django pip install django

Install django and debugging tools

Now let's talk about installing django and its related tools.

Django installation is also very simple. You can download the latest version from the official https://www.djangoproject.com/download/directly. The installation method is also described on the official website. You can use pip or git to install the tool. I am still used to installing the installation package.






After downloading the required installation, go to the relevant directory and use python setup. py install. After the installation is complete, run the command to obtain the installed django version.

Python-c "import django; print django. VERSION"

(1, 7, 4, 'final', 0)


Use the command django-admin.py startproject liuxin to create a liuxin project, as to the configuration files under the project, will be discussed later. Go to the created Project and run the python manage command. py runserver can run django's development server. In the browser, visit http: // 127.0.0.1: 8000/and see the prompt "Welcome to Django.


So far, django has been installed. Now let's talk about the installation of django-debug-toolbar.

Run the easy_install django_debug_toolbar command to install the tool. It is easy to install and requires configuration.

Go to the project you just created and edit the settings. py file as follows.

The debug_toolbar line is a tool for django_debug_toolbar.


INSTALLED_APPS = (

'Django. contrib. admin ',

'Django. contrib. auth ',

'Django. contrib. contenttypes ',

'Django. contrib. session ',

'Django. contrib. messages ',

'Django. contrib. staticfiles ',

'Debug _ toolbar ',

'Debugtool'

)







The last line of debug_toolbar.middleware.DebugToolbarMiddleware is the tool for django_debug_toolbar.


MIDDLEWARE_CLASSES = (

'Django. contrib. sessions. middleware. SessionMiddleware ',

'Django. middleware. common. CommonMiddleware ',

# 'Django. middleware. csrf. CsrfViewMiddleware ',

# 'Django. middleware. csrf. CsrfResponseMiddleware ',

'Django. contrib. auth. middleware. AuthenticationMiddleware ',

'Django. contrib. auth. middleware. SessionAuthenticationMiddleware ',

'Django. contrib. messages. middleware. MessageMiddleware ',

'Django. middleware. clickjacking. XFrameOptionsMiddleware ',

'Debug _ toolbar. middleware. DebugToolbarMiddleware ',

)



After editing, you need to add another line of INTERNAL_IPS = ('192. 0.0.1 ',). The ip here indicates that the ip address of the django_debug_toolbar tool can be used. Note that the IP address is followed by a comma, because this is a tuple variable. After running the development server, the django_debug_toolbar tool is displayed on the right.









Let's talk about another Django debugging tool, debugtools.

Its installation is similar to that of toolbar, pip install django-debugtools.

Then, add 'destogtools' in INSTALLED_APPS in setting. py. As mentioned above, I will not go into detail here.


After setting it, let's see if you want to use it. Add {% print login_err %} to the html template. Here, login_err is a variable and can be adjusted as needed on the html page to be debugged.






Because the login interface is just opened, there is no wrong variable yet. Here, you can intentionally enter a wrong variable to display it.

The following figure shows that the variable content is displayed on the front-end page. This is a very practical function, and we can easily find the cause when debugging the problem.





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.