Django Development Blog-Deployment

Source: Internet
Author: User
Tags install django pip install django version control system virtualenv

Install Git

Git is a "version control system" that is used by a large number of programmers. This software can track changes to any time file, so you can recall a specific version at any point in the future.

GIT-SCM installation can be downloaded under Windows System. In addition to the 5th step, "Adjusting your PATH environment", you need to select "Run Git and associated Unix tools from the Windows command-line" (bottom option). In addition, the default value is fine.

Installation of Linux system using Package Manager

1
2
3
sudo apt-get install git
# or
sudo yum install git

Git repository

First initialize the warehouse

1
2
3
4
$ git init
In ~/simpleblog/.git/
"YIDAO620C"
$ git config--global user.email [email protected]

We only need to initialize the GIT repository once per project (and you never have to re-enter your username and mailbox)

Git keeps track of changes to all files and folders in this directory, but there are some files we want Git to ignore. To do this, we can create a file named at the root .gitignore of the system. Open the editor, create a new file, and write the following:

Myvenv
. idea/
*.pyc
__pycache__
Staticfiles
local_settings.py
Db.sqlite3
Migrations
whoosh_index/

Finally, save our changes. Go to your console and run these commands:

1
2
$ git add--all.
"My Simple Blog First Commit"

Push on to GitHub

Login to the github.com website, if not, register one first. Create a new warehouse name for simpleblog , in the next screen, you will see your repository clone URL. Select "HTTPS" version, copy the address, we will paste it into the terminal immediately

Enter the following in the console (replace with your GitHub user name, without the angle brackets):

1
2
$ git Remote add Origin https://github.com/yidao620c/simpleblog.git
$ Git push-u Origin Master

Enter your GitHub account name and password, and you will see a successful message stating that there is no problem.

Set up our blog at Pythonanywhere

First go to the site to register a user name, free users can.

Pull our code on the Pythonanywhere

Of course, after registering for Pythonanywhere, you will go to the dashboard or "console" page. Choose the option to launch the Bash console, which is the Pythonanywhere version of the console, just like on your local computer.

1
Clone Https://github.com/yidao620c/simpleblog.git

This will pull a copy of your code to Pythonanywhere. By typing the tree simpleblog lookup

Every time you need to update the next time to execute

1
Git pull

Create a virtualenv on Pythonanywhere

As you do on your own computer, you can create virtualenv virtual environments on Pythonanywhere. Under Bash console, type:

1
2
3
4
CD Simpleblog
Virtualenv--python=python3.4 myvenv
SOURCE Myvenv/bin/activate
Pip Install Django

Note the PIP installation steps may take several minutes. Wait patiently! But if more than 5 minutes, it is not right, to check the network reasons.

Create a database on Pythonanywhere

The other thing that the server differs from your own computer is that it uses a different database. So the user account and the article may be different from the one on your computer.

We can initialize the database on the server just like on our own computer, using migrate and Createsuperuser:

1
2
(mvenv) $ python manage.py migrate
(mvenv) $ python manage.py createsuperuser

Publish a blog

Now that our code is on Pythonanywhere, our virtualenv is ready, the static file has been collected, and the database has been initialized. We are ready to publish the Web application!

Return to the Pythonanywhere dashboard by clicking on the logo, then click on the Web tab. Finally, click Add a new Web App

After confirming your domain name, select Manual configuration in the dialog box (note not "Django" option), next select Python 3.4, then click Next to complete the wizard.

Set virtualenv

You will be taken to Pythonanywhere on your Web application's configuration screen, which is the page you want to go to whenever you want to modify your application on the server.

In the "Virtualenv" section, click the red text "Enter the path to a virtualenv" and type:/home//simpleblog/myvenv/. Before moving forward, click the Blue box with a check box to save the path.

Configuring the WSGI File

Django uses the "WSGI Protocol", which is a standard used to serve Python websites. Pythonanywhere supports this standard. The way Pythonanywhere identifies our Django blog is by configuring the Wsgi configuration file.

Click the "WSGI configuration File" link (in the "Code" section, it will be named as/var/www/_pythonanywhere_com_wsgi.py) and then jump to an editor.

Delete all the content and replace it with the following:

1
2
3
4
5
6
7
8
9
10
11
12
Import OS
Import Sys

Path = '/home/<your-username>/my-first-blog ' # your own username here
If path not in Sys.path:
Sys.path.append (PATH)

os.environ['django_settings_module '] = ' mysite.settings '

From Django.core.wsgi Import get_wsgi_application
From Django.contrib.staticfiles.handlers Import Staticfileshandler
application = Staticfileshandler (Get_wsgi_application ())

Note: When <your-username> you see it, don't forget to replace it with your own user name.

The purpose of this file is to tell Pythonanywhere where our web application is, and what the name of the Django settings file is. It also sets the "Whitenoise" Static file tool.

Click Save and return to the Web tab.

It's all done! Click on the Big Green Reload button and you will see your app. You can see its link at the top of the page.

Debugging Tips

If you see a bug when you visit your website, first go to error log to find some debugging information. You can find its link in the Pythonanywhere web tab. Check if there are any error messages, the bottom is the latest information. Frequently asked questions include:

    • Forget our steps in the console: Create a virtualenv, activate it, install Django, run collectstatic, migrate the database.
    • In the Web tab, the VIRTUALENV path is set incorrectly-if so, this is usually a red error message.
    • WSGI File Set error-Is your Simpleblog directory address set correctly?
    • Did you choose the same Python version for your virtualenv as in the Web application? Two should all be 3.4.
    • There are some common debugging tips on the pythonanywhere in debugging tips.
You're on the line!

The default page of your site says "Welcome to Django," as you would on your local computer. Try adding/admin/to the end of the URL, and you'll get to the manager's page. Enter the username and password to log in, and then you will see the add new Posts on the server.

Django Development Blog-Deployment

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.