Diễn đàn    Lập trình Python / Postgres SQL    Django là web server cho python

lenh_ho_xung

Tieu ngao giang ho

42  bài
9-10-2017 18:29:9
Giống trên windows, người lập trình dùng web server IIS cho asp.net. Còn với python chúng ta dùng django (ngoài ra có Flesk). Để cài đặt ta cài pip.

$pip install Django
 
aspnet

Lập trình không biên giới

608  bài
9-10-2017 20:15:1
kiểm tra django dùng :

$ python -m django --version

tạo 1 website với django :

$ django-admin startproject mysite

Sau khi tạo xong chúng ta sẽ có 1 folder như sau :

mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py

Load web site của chúng ta lên bằng lệnh ( vào folder mysite vừa tạo )

$ python manage.py runserver.

kết quả là :

==========

It worked!
Congratulations on your first Django-powered page.

Next, start your first app by running python manage.py startapp [app_label].

You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!

---
Cây sẽ cho lộc và cây sẽ cho hoa ...
 
aspnet

Lập trình không biên giới

608  bài
9-10-2017 20:16:43
Nếu gặp lỗi như hình dưới ;



Django RuntimeError: maximum recursion depth exceeded

Thì chúng ta mở file 'functools.py' và sửa

=====
convert = {
'__lt__': [('__gt__', lambda self, other: other < self),
('__le__', lambda self, other: not other < self),
('__ge__', lambda self, other: not self < other)],
'__le__': [('__ge__', lambda self, other: other <= self),
('__lt__', lambda self, other: not other <= self),
('__gt__', lambda self, other: not self <= other)],
'__gt__': [('__lt__', lambda self, other: other > self),
('__ge__', lambda self, other: not other > self),
('__le__', lambda self, other: not self > other)],
'__ge__': [('__le__', lambda self, other: other >= self),
('__gt__', lambda self, other: not other >= self),
('__lt__', lambda self, other: not self >= other)]
}

thành ra ;
=====
convert = {
'__lt__': [('__gt__', lambda self, other: not (self < other or self == other)),
('__le__', lambda self, other: self < other or self == other),
('__ge__', lambda self, other: not self < other)],
'__le__': [('__ge__', lambda self, other: not self <= other or self == other),
('__lt__', lambda self, other: self <= other and not self == other),
('__gt__', lambda self, other: not self <= other)],
'__gt__': [('__lt__', lambda self, other: not (self > other or self == other)),
('__ge__', lambda self, other: self > other or self == other),
('__le__', lambda self, other: not self > other)],
'__ge__': [('__le__', lambda self, other: (not self >= other) or self == other),
('__gt__', lambda self, other: self >= other and not self == other),
('__lt__', lambda self, other: not self >= other)]
}

là fix xong lỗi.
---
Cây sẽ cho lộc và cây sẽ cho hoa ...
 
aspnet

Lập trình không biên giới

608  bài
9-10-2017 20:19:35
Đặt tham số Path cho python :

Mở Win start - View advance settings - Advance - Enviroment variables ..

thêm ';c:\python27\python.exe' vào là xong
---
Cây sẽ cho lộc và cây sẽ cho hoa ...
 
aspnet

Lập trình không biên giới

608  bài
9-10-2017 20:21:2
Muốn chọn cổng cho django thì dùng lệnh :

$ python manage.py runserver 8069

là django sẽ run ở cổng 8069.
---
Cây sẽ cho lộc và cây sẽ cho hoa ...
 
Tên file Mô tả chi tiết Ngày
NWeb.zip (1) Module đơn giản Newsweb trên Dotnetnuke v10.x.x.x10/18/2025 8:08:11 AM
vspforum.zip (11) Ma nguon vspforum ngay xua4/18/2023 6:38:37 AM
pdfjs.rar (2) pdfjs 2017 : hiển thị tốt trên iphone 11, 12, 13 không lỗi, bản 2012 sẽ lỗi trên iphone6/21/2022 11:52:48 AM
pdfjs2.rar (2) Xem file pdf bằng viewer.hml cua pdfjs (thư viện chuẩn mozilla) 2012. https://mozilla.github.io/pdf.js/getting_started/#download có thể download bản prebuild tại đây6/21/2022 11:52:04 AM
runner.zip (0) using three.js, orbitcontrol to view an object move random on map. Di chuyển 1 đồ vật ngẫu nhiên trên bản đồ, sử dụng với demo nhân viên di chuyển trong văn phòng. Toàn js download về là chạy12/5/2019 5:55:14 PM
gmap.zip (1) google map + marker7/17/2019 2:25:05 PM
vinsmarthomeservice.zip (1) java post json to api, use AsyncTask, event listener7/9/2019 5:00:10 PM
fblogin.zip (0) Login facebook bang javascript SDK7/9/2019 9:16:37 AM
autocomplete-location.zip (2) autocomplete location geo from google place, html + js7/4/2019 4:37:55 PM
WebAPI.zip (8) api for android access db (v1.0.0)7/4/2019 9:14:17 AM