Run the server and visit http://127.0.0.1:8000/admin/
如果发生TemplateDoesNotExist at /admin/login/错误
from django.contrib import admin from blog.models import Category, Article # Register your models here. admin.site.register(Category) admin.site.register(Article)
you can check out the official Django documentation on the admin interface for more information if you’re interested.
Now that we’ve covered the core principles of dealing with Django’s models functionality, now is a good time to summarise the processes involved in setting everything up. We’ve split the core tasks into separate sections for you.
With a new Django project, you should first tell Django about the database you intend to use (i.e. configure DATABASES in settings.py). You can also register any models in the admin.py file to make them accessible via the admin interface.
The workflow for adding models can be broken down into five steps.
Invariably there will be times when you will have to delete your database. In which case you will have to run the migrate command, then createsuperuser command, followed by the sqlmigrate commands for each app, then you can populate the database.
Undertake the part two of official Django tutorial if you have not done so.
在PersonalWebsite/settings.py里声明你的数据库
DATABASES = {
'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } }
挪到服务器上的话最好用MySQL之类 https://docs.djangoproject.com/en/1.7/ref/settings/#std:setting-DATABASE-ENGINE
To create a population script for Rango’s database, we start by creating a new Python module within our Django project’s root directory (e.g. <workspace>/tango_with_django_project/). Create the populate_rango.py file and add the following code.
import os os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tango_with_django_project.settings') import django django.setup() from rango.models import Category, Page def populate(): python_cat = add_cat('Python') add_page(cat=python_cat, title="Official Python Tutorial", url="http://docs.python.org/2/tutorial/") add_page(cat=python_cat, title="How to Think like a Computer Scientist", url="http://www.greenteapress.com/thinkpython/") add_page(cat=python_cat, title="Learn Python in 10 Minutes", url="http://www.korokithakis.net/tutorials/python/") django_cat = add_cat("Django") add_page(cat=django_cat, title="Official Django Tutorial", url="https://docs.djangoproject.com/en/1.5/intro/tutorial01/") add_page(cat=django_cat, title="Django Rocks", url="http://www.djangorocks.com/") add_page(cat=django_cat, title="How to Tango with Django", url="http://www.tangowithdjango.com/") frame_cat = add_cat("Other Frameworks") add_page(cat=frame_cat, title="Bottle", url="http://bottlepy.org/docs/dev/") add_page(cat=frame_cat, title="Flask", url="http://flask.pocoo.org") # Print out what we have added to the user. for c in Category.objects.all(): for p in Page.objects.filter(category=c): print "- {0} - {1}".format(str(c), str(p)) def add_page(cat, title, url, views=0): p = Page.objects.get_or_create(category=cat, title=title)[0] p.url=url p.views=views p.save() return p def add_cat(name): c = Category.objects.get_or_create(name=name)[0] return c # Start execution here! if __name__ == '__main__': print "Starting Rango population script..." populate()
在PersonalWebsite, blog, templates平行下建立static/images,并放入一张图片cat.png
编辑settings.py
STATIC_PATH = os.path.join(BASE_DIR,'static') STATIC_URL = '/static/' STATICFILES_DIRS = ( STATIC_PATH, )
在index.html中: html外写{% load staticfiles %}, body里加入<img src="{% static "images/cat.png" %}" alt="Picture of Cat" />
we need to inform Django’s template system that we will be using static media with the {% loadstatic %} tag. This allows us to call the static template tag as done in {% static "rango.jpg" %}. As you can see, Django template tags are denoted by curly brackets { }. In this example, the static tag will combine the STATIC_URL with "rango.jpg" so that the rendered HTML looks like the following
如何调用javascript和css
如果要放在服务器上,请参考
关于Deploy #TODO(leifos): the DEBUG variable in settings.py, lets you control the output when an error occurs, and is used for debugging. When the application is deployed it is not secure to leave DEBUG equal to True. When you set DEBUG to be False, then you will need to set the ALLOWED_HOSTS variable in settings.py, when running on your local machine this would be 127.0.0.1. You will also need to update the project urls.py file:
上传Media 与static, templates并列建立文件夹media; 在PersonalWebsite/urls.py里加入
# At the top of your urls.py file, add the following line: from django.conf import settings # UNDERNEATH your urlpatterns definition, add the following two lines: if settings.DEBUG: urlpatterns += patterns( 'django.views.static', (r'^media/(?P<path>.*)', 'serve', {'document_root': settings.MEDIA_ROOT}), )
The settings module from django.conf allows us access to the variables defined within our project’s settings.py file. The conditional statement then checks if the Django project is being run in DEBUGmode. If the project’s DEBUG setting is set to True, then an additional URL matching pattern is appended to the urlpatterns tuple. The pattern states that for any file requested with a URL starting with media/, the request will be passed to the django.views.static view. This view handles the dispatching of uploaded media files for you.
编辑PersonalWebsite/settings.py 加入
MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # Absolute path to the media directory
Summary
Creating a template and integrating it within a Django view is a key concept for you to understand. It takes several steps, but becomes second nature to you after a few attempts.
The steps involved for getting a static media file onto one of your pages is another important process you should be familiar with. Check out the steps below on how to do this.
First, create the template you wish to use and save it within the templates directory you specified in your project’s settings.py file. You may wish to use Django template variables (e.g. {{variable_name }}) within your template. You’ll be able to replace these with whatever you like within the corresponding view.
Find or create a new view within an application’s views.py file.
Add your view-specific logic (if you have any) to the view. For example, this may involve extracting data from a database.
Within the view, construct a dictionary object which you can pass to the template engine as part of the template’s context.
Make use of the render() helper function to generate the rendered response. Ensure you reference the request, then the template file, followed by the context dictionary!
If you haven’t already done so, map the view to a URL by modifying your project’s urls.py file - and the application-specific urls.py file if you have one.
Take the static media file you wish to use and place it within your project’s static directory. This is the directory you specify in your project’s STATICFILES_DIRS tuple within settings.py.
Add a reference to the static media file to a template. For example, an image would be inserted into an HTML page through the use of the <img /> tag.
Remember to use the {% load staticfiles %} and {% static "filename" %} commands within the template to access the static files.
2018年6月18日 23:35
The new programmer has been stepping in the market. The use of the concept and online assignment writing service has been identified for the use of the forms for the humans. The nature of the problem is divided for the use of the strong hold for the humans in life.
2018年7月24日 07:17
I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site. <a href="https://www.naturalfoodseries.com/10-benefits-cucumber-juice">Cucumber Juice</a>
2018年8月16日 07:22
Best place to use the free psn free codes on our site and do enjoy.
2018年10月11日 20:11
Love is singing for the pain is beautiful, no day no month pen name ...
2019年4月04日 12:37
The primary concern is, they can put a more expensive rate and influence a superior benefit on the off chance that they to overlook the oil based, engineered SBR content... or on the other hand simply imagine that it doesn't exist! best latex mattress
2019年5月22日 01:56
Thanks for the essential information.
2019年6月17日 00:42
While these things may at present exist, they are not the influx of things to come.
www.chennel-tv.com <a href="http://www.chennel-tv.com">live channels</a>2022年1月27日 02:38
idrive support , amazon prime customer service number , tech support number , contact instagram, cisco support , aol customer service , norton support , mcafee support , epson printer support , hp support , apple icloud support , hewlett packard customer service , carbonite phone number , lexmark support , www tomtom com support , asus customer service , pogo support , arlo support , webroot customer service,
technical support number, contact support phone number, technical support phone number
contact apple support icloud, apple icloud support email address, apple icloud support phone number uk, apple phone number for icloud support,
Google Hangouts customer service number, hangouts support, hangouts web chat, hangouts online chat,
idrive contact, idrive phone number, idrive customer support,
google drive contact number, google drive help number, google drive customer support phone number, call google drive,
amazon prime customer support phone number, amazon prime customer number, amazon prime support phone number, amazon prime customer phone number,
pogo phone number, pogo customer service phone number, pogo technical support phone number, pogo customer service,
trend micro download, trend micro for mac, uninstall trend micro, trend micro account login,
Travel PPC calls ,
Travel Calls Campaign ,
PPC for travel ,
PPC for travel industry ,
travel ppc campaign ,
travel ppc ,
best travel campaigns ,
travel marketing campaigns ,
ppc travel ,
travel ppc agency ,
travel campaign ,
Travel calls ,
2022年1月27日 02:39
nuance technical support , match phone number , , skype number, q see customer service , google voice setup , snapchat help , google voice setup , tinder customer service , support avast com , support dlink , OEM support , qsee customer service , skype customer service, match com customer service number , nuance customer service , snapchat contact , google voice phone number , tinder contact ,
avast customer service, support avast com, avast support, avast phone number, avast forums,
customer service number ,customer support number ,customer service phone number ,customer support phone number , independent support
q see customer support number ,q see live chat ,q see chat support , qsee support
2022年1月27日 02:39
skype support number ,skype customer service 1 800 ,skype support chat , skype phone number
contact match by phone ,match customer care ,contact match , match customer service
dragon naturally speaking technical support ,dragon naturally speaking phone number ,dragon naturally speaking support phone number , nuance support
snapchat contact us ,snapchat customer support ,snapchat help center , snapchat support ,
google voice contact number ,google voice toll free number ,google voicemail number , google voice number
tinder help email ,email tinder ,tinder helpline , tinder support
2022年1月27日 02:40
microsoft edge , Microsoft Edge help , microsoft edge for mac , edge for mac , edge browser for mac , mac edge , edge on mac , windows edge , edge windows 10 , microsoft edge browser , uninstalling microsoft edge , installing microsoft edge , uninstalling edge , reinstalling microsoft edge , removing edge from windows 10 , microsoft edge update , updating edge
2022年1月27日 02:40
Chrome slowness , Chrome help , Google chrome support , chrome download , download chrome for mac , download google chrome for windows , google chrome download , chrome browser download , chrome download for pc , how to download google chrome , download google chrome for windows 10 , install chrome , install google chrome , install chrome on mac
2022年1月27日 02:40
netgear customer service ,netgear support number ,netgear customer support ,netgear support phone number
norton security phone number ,norton phone number ,norton support ,norton setup
facebook phone number ,facebook help ,how to contact facebook ,facebook customer service phone number
contact match by phone ,match customer care ,contact match ,how to cancel match ,
toshiba customer service phone number ,toshiba contact number ,toshiba printer support ,toshiba customer care number
lenovo support number ,lenovo customer service number ,lenovo customer support ,lenovo support drivers
2022年1月27日 02:41
tinder contact , webroot phone number , twitter help , dlink router setup , google voice phone number , samsung phone number , youtube phone number ,
call roku ,roku tech support number ,roku tv customer service ,roku tv support
mcafee customer service ,mcafee phone number ,mcafee support number ,mcafee customer service number
snapchat number ,snapchat customer service ,snapchat phone number
2022年1月27日 02:41
OEM support , gmail support , Official support , tinder customer service , google voice setup , contact twitter , webroot support , d-link support , webroot customer service , contact yahoo , toshiba customer service , snapchat help . roku customer service phone number , facebook phone number , norton security phone number , netgear customer service , mcafee customer service , match phone number , lenovo support number , hotmail customer service , contact youtube , gmail setup , panasonic phone number , pinterest phone number
2022年1月27日 02:42
Firefox setup , Firefox help , firefox support , firefox , firefox download , firefox for mac , mozilla firefox download , mozilla firefox for mac , download firefox for mac , download firefox for windows , mozilla firefox download for windows , firefox download for windows 10 , mozilla download , firefox free download , firefox latest version , firefox old version download , download mozilla firefox for mac
2022年1月27日 02:42
microsoft edge , Microsoft Edge help , microsoft edge for mac , edge for mac , edge browser for mac , mac edge , edge on mac , windows edge , edge windows 10 , microsoft edge browser , uninstalling microsoft edge , installing microsoft edge , uninstalling edge , reinstalling microsoft edge , removing edge from windows 10 , microsoft edge update , updating edge
2022年1月27日 02:42
safari support , safari frozen on mac , too many redirects safari , safari problems , safari not working on iphone , safari not working on mac , safari not working , safari not working on ipad , safari not responding on mac , my safari is not working , safari google search not working , safari not responding , macbook safari not working , safari not loading pages on iphone , safari not loading pages
2022年1月27日 02:42
dietitian in delhi , best dietitian in delhi , top dietician in india , top dietician in delhi
best foods to gain weight , gain weight fast , increase weight , best diet for weight gain , muscle gain diet plan
types of therapeutic diet , therapeutic diet , therapeutic nutrition ,
how to lose weight after c section delivery , post delivery weight loss , weight loss after c section delivery ,
2022年1月27日 02:43
nutritionist
weight loss after delivery
weight management
diet for diabetes
weight loss
pcos diet plan
hypothyroidism diet
high blood pressure diet
to gain weight
diet for diabetes
diabetic diet plan for weight loss ,
2022年1月27日 02:43
samsung laser printer customer care number ,samsung printer call center ,samsung printer contact ,samsung printer number
sharp printer customer service ,sharp printer customer care number , sharp customer service , sharp support ,
hewlett packard support number, hewlett packard support phone number , hewlett packard customer service, hewlett packard support,
hp printer phone support, hp support printer, hp printer service center, hp wireless printer support, hp printer customer support
brother printer help
toshiba support drivers
sharp contact
Printer technical support
2022年1月27日 02:43
contact epson, epson contact number, epson printer customer support number, epson printer support number,
kyocera customer service phone number, kyocera contact number, kyocera customer support, kyocera help, kyocera number,
panasonic customer care number, panasonic telephone number, panasonic printer customer service , panasonic customer service , panasonic support,
panasonic customer care number, panasonic telephone number, panasonic printer customer service , panasonic customer service , panasonic support,