Python djan library operation process

Source: Internet
Author: User
Tags netbeans

Python django requires us to learn related technologies during continuous construction. Next, let's take a detailed look at the specific content. Recently, I have encountered many difficulties in learning the python django WEB development framework. I would like to review it here. Maybe you are worried about these problems?

When using the NetBeans for python django Library as the editor, you will find that all the entered Chinese characters have become small boxes ···

Solution: copy the corresponding fonts in the system to the jdk directory, open the terminal, and enter: mkdir {JAVA_HOME}/jre/lib/fonts/fallback

Note that {JAVA_HOME} is replaced with your jdk main directory. After mkdir is executed, enter:

 
 
  1. cp /usr/share/fonts/truetype/arphic/uming.tcc {JAVA_HOME}/j
    re/lib/fonts/fallback 

Restart netbeans and try again. Should I be able to enter Chinese characters?

Generally, when reading python related information, you will be reminded that the pythondjango code is strictly indented, but you must not care about it? Once I added the admin application to the django project and configured the url ing, there was always an Access Error. After checking several times, no code logic problems were found, at last, the indentions are invalid in the error prompt. contrib .... there is a space in front of this sentence.

Solution: Remove Spaces

When you create a django project and write a view, do you find any Chinese characters in the project during the test? The access will fail, but the compilation is normal? This is because the default encoding does not support Chinese characters.

Solution: Add the following two lines at the beginning of the file:

 
 
  1. #!/usr/bin/env python  
  2. # -*- coding: utf-8 -*- 

When creating the Category model, if you want to inherit itself to implement recursive wireless classification, you enter parent = models. foreignKey ('self ', null = True, verbose_name = "parent class ID ")

However, when you go to the admin background to create a Category, you will find that the first Category is blocked, prompting you to select a parent class. Since it is the first one, how can we select the parent class .. Is it null = True? Can it be null )?

Solution: Add blank = True, for example, parent = models. ForeignKey ('self ', null = True, blank = True, verbose_name = "parent class ID ")

Since django has always recommended PostgreSQL database, it is also an excellent open source database, so we need to learn to use it. Django needs to use the psycopg2 library for PostgreSQL operations;

 
 
  1. tar zxvf psycopg2-2.0.13.tar.gz  
  2.  
  3. cd psycopg2-2.0.13  
  4.  
  5. python setup.py install  
  6.  

The above steps are the general python django library installation method, but I do not know why I always prompt No such file or directory

Solution: Use a text editor to open setup. cfg $ vim setup. cfg), find # pg_config =, remove the previous #, and set the value:

 
 
  1. Pg_config =/{Your PostgreSQL installation directory}/bin/pg_config

Save the settings and run python setup. py install again. This time it should be OK.

This article is worth recording and will be updated at any time. You are also welcome to study the python django library to discuss the issue and make progress together.


 

Related Article

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: [email protected] 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.