开发一个Django项目流程

  1. 新建一个django项目
  2. 配置项目的运行环境,Python解释器:
    • settings:Language & Frameworks->Django->Django project root;Settings
    •                 Project:******->Project Interpreter->Project Interpreter:选择相应的python解释器
    • Run->Edit configurations->"+"Python->Name:**;Script path:项目目录\manage.py;Parameters:runserver;Python interpreter:Python解释器
  3. 新建app:   Terminal:python manage.py app_name:
  4. 配置主目录settings.py:INSTALLED_APPS中添加 ‘app_name’,;
  5. 配置主目录urls.py:urlpatterns中添加:url(r'',include('app_name.urls')),
  6. 连接redis: 
    1. 定义redis集群:redis_node=[{},{},{}];密码:redis_password
    2. 添加rediscluster框架:redis-py-cluster
    3. 连接redis:
      try:
          redisconn = RedisCluster(startup_nodes=redis_nodes,decode_responses=True, password=pd, max_connections=150)
      except Exception:
          print("Connect Redis Error")
  7. 针对每一个功能的app:
    1. 新建serializers.py:(类似于form表单)(待编辑。。。。。。。。。。。。。)
    2. 编辑views.py:编写功能对应视图函数:
    3. class RecSingleView(APIView):
          def post(self, request,format=None):
              pass
    4. 编辑urls.py:定义视图函数对应的urls
    5. urlpatterns=[
          url(r'^rec-single/',RecSingleView.as_view())
      ]

猜你喜欢

转载自www.cnblogs.com/yujiebingqing/p/9634616.html