Dear friends, I used to create a project: Because tables are not associated, we use non-relational database mongodb. the project development environment uses python + django and is deployed on ubuntu. At that time, pymongo was used to connect python to mongodb, and the engine was used to connect django to
query for all British users older than or equal to 18 years old, or all users older than or equal to 20 years old. From mongoengine.queryset.visitor import q user.objects ((q (country= ' UK ') Q (age__gte=18)) | Q (AGE__GTE=20))# Sort from datetime import datetimeClass blogpost (Document):title = Stringfield ()Published_date = Datetimefield ()Meta = {' Ordering ': ['-published_date ']} blog_post_1 = blogpost (title= "blog post #1") Blog_post_1.published_date = DateTime (1, 5, 0, 0, 0) blog_pos
indicates the minimum version of the request, and the server will return all data with a version greater than or equal to 0 when the request is received.First, add a URL rule to url.pyURL (r ' ^download/(? pThen add the function to the view.py download_kanjidef Download_kanji (Request, version=0): kanji = _mongo.get_kanji (int (version)) return HttpResponse (Kanji, Content_type= "Application/json")Read data greater than or equal to versiondef Get_kanji (self, version): # Check pending
Tags: ice pip sts Ram Model content pip install Image awl1. Introduction It used to be developed using the django+ relational database MySQL, which now requires the use of django+ non-relational database MongoDB, which can be used directly in Django for MySQL operations, but Djang
minimum version number of the request, and the server will return all data with a version number greater than or equal to 0 when it receives the request.First, add a URL rule in url.pyURL (r ' ^download/(? pThen add the function in the view.py download_kanjidef Download_kanji (Request, version=0): kanji = _mongo.get_kanji (int (version)) return HttpResponse (Kanji, Content_type= "Application/json")Read data greater than or equal to versiondef Get_kanji (self, version): # Check pending
First, the Environment Basic step 1, enter the development environment of the virtual space, do not know see the transmission Door 2, the version of the basic package
django@1.11.8 mongoengine@0.15.0
3. Installation package
Pip Install Mongoengine4, create a new Django project, and specify the Python.exe in the virtual space Two, configure in Django
1, in the set
Tags: setting blog class Mon settings Ali imp must have aUse the Mongoengine module when using the MongoDB database in Djnago. In Settings, configure the database connection as follows: from Import connectconnect ('dbname1', host='127.0.0.1', port= 27017)The dbname1 is the name of the MongoDB database to be connected, and the host Ip,port the MongoDB database as
=request. files[' Proupload '].name Uploaded_file (Request. files[' Proupload '],filename) post.proadress = filename Return Render_to_response (' xxx.html ', locals ())
Description: The filename in the method above is the file name that was uploaded, including the file suffix, such as test.txt. Request. files[' Proupload ') is a file that was obtained with the name Proupload. The result is that the uploaded file is stored in a locally pinned location, and a file name i
Startup scripts
#!/usr/bin/env pythonfrom gevent Import Monkey; Monkey.patch_all () from gevent import wsgifrom mysite.wsgi Import applicationhost = ' 127.0.0.1 ' PORT = 8080# set Spawn=none For Memcachewsgi. Wsgiserver (HOST, PORT), application). Serve_forever ()
Gevent is a greenlet-based Python concurrency framework that uses the Epoll event monitoring mechanism and many other optimizations to be efficient, with a micro-threading Greenlet as its core.
Official website: http://www.dj
1. Create an app, Python manage.py startapp appname
2. Design model, edit the model in the appname/directory
3. Detection of model changes, Python manage.py makemigrations appname
4. Automating database migrations and synchronizing the management database structure, Python manage.py sqlmigrate 0001
5. Create a data table for the newly defined model in the database Python manage.py migrate
Steps to change the model:
Edit the models.py file to change the model.
Run python manage.py mak
1 WSGI#WSGI (is a set of protocols, many things such as Wsgiref, uwsgiref follow this set of protocols)-the Django system is essentially someone's socket (wsgiref or uwsgiref)+Django-The simple definition of WSGI (Web server Gateway Interface) is a specification that defines the interface format between Web apps and Web servers written in Python, enabling Web apps and Web Ser Decoupling between the Ver.
[Django advanced] Understand the middleware mechanism and execution sequence in django, and django Middleware
The original Article is from Understanding Django Middlewares. This article introduces the definition and function of middleware in django and how to write the m
Use django-suit to add a template for the django 1.7 admin background, django-suitdjango
It seems a bit problematic to use inline in django-grappelli. For another skin:
Django-suit is the second admin skin recommended by 2scoops.Supports:
Tags: def perform cat way Django Registration GIS Upper has a1 Template Introduction Sub Html--include 7Template engine-Master Version-include, import the common HTML A. Usage: {% include"pub.html"%}, pub.html can also add {{name}} B. A page can be imported multiple times, and an HTML can have only one master C. Example # Public. htmlclass=" Public"> class="content">{{UserInfo}}# app02_test.html
{% include"public.html"%}
User Management Section of Django's blog website (using its own django. contrib. auth) 1. Registration Section, django. contrib. auth
Project tool: Python 2.7.11 Django 1.10.2 Bootstrap 3.3.0 IDE: eclipse Pydev
1. Make sure that 'django. contrib. auth' already exists in settings'
For example:
Settings in myproject
1 I
To install Django2 using PIP:pipinstalldjangoError:
Collecting DjangoUsing Cached django-2.0.tar.gzComplete output from command python setup.py egg_info:Traceback (most recent):File "File "django/setup.py", line +, in Version = __import__ (' Django '). Get_version ()File "django/__init__.py", line 1, From django.ut
Python Study Notes _ 04: Django framework introduction, _ 04 django
Directory1. What is Django?2. Build a development environment for the Django framework3 Introduction to Django operations on MySql Databases4. Powerful Django man
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.