How do I make a project in Django? Beginner
Okay I just started with Django and it's totally different from PHP. I installed Python 2.6 and Django.
Both are located in my C drive.
C:
Django
build
django
bin
django-admin.py
docs
Python26
I am doing the django site tutorial and when they say to write django-admin.py startproject mysite from my Python command line, I getting errors.
My django-admin.py is in the django/b开发者_如何转开发in folder. I installed Python via python setup.py. How do I create a project with django?
Thanks :)
You've got to run that from a command line, not within the python interpreter!
From the docs:
From the command line, cd into a directory where you’d like to store your code, then run the command django-admin.py startproject mysite. This will create a mysite directory in your current directory.
So from the C prompt:
python django-admin.py startproject mysite
You might need to add the path to django-admin
Seems like you have not added C:\python26 or wherever you have installed your python to the PATH .... you can edit the path from cmd or by right-clicking My Computer and going to environment variable tab from properties...add both python path and django path where u have your admin.py
it is very easy to make a python django project
run terminal in you linux or mac box
first:
django-admin.py startproject mysite
mysite is a project name
second: in python django project, each and every feature should be start in an app, so our next work is create a app. here polls is a app entered your project folder and run
python manage.py startapp polls
python manage.py syncdb
then just run the project
python default run on 8000
port. you also define port like this way
python manage.py runserver 6006
go your browser and hit http://127.0.0.1:6006
next step is configure the project and manage the project. you have to change some change in settings.py
and urls.py
Your virtual Environment will contain these three folder:
1)Include
2)Lib
3) Scripts
(Read about them from django official website)
What you need to do is use all these 3 things.
On your command line cd
into your virtual environment folder.Then use this code:
python Scripts\django-admin.py startproject mysite
Output: A folder named "mysite" will be created inside your virtual environment.And because this folder is inside virtual environment, you will be able to use all 3 components.
Boilerplate Code To create django as well create django app you have to follow many common commands. for simplicity, kindly follow the below single-line commands separated by semicolon:
django-admin startproject project_name; cd project_name;python3 manage.py startapp app_name; cd app_name; mkdir templates
Those commands will create commonly used structure for django.
Create a virtual environment
python3 -m venv my-env
Activate the my-env
Source my-env/bin/activate
Install Django in my-env
pip install django
Check the version
django-admin --version
Crarte folder in my-project
$ cd my-project
Then
$ django-admin startproject my-project-name
$ cd my-project-name
$ python manage.py runserver
Then open browser and type url http://127.0.0.1:8000/ or http://localhost:8080
精彩评论