123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- UBUNTU DJANGO-website
- https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django
- ```bash
- sudo apt install mariadb-client mariadb-server libmariadbclient-dev
- sudo pip3 install mysqlclient
- sudo mysql_secure_installation
- sudo mysql -u root
- ```
- ```mysql
- USE mysql;
- CREATE USER 'pbarriat'@'localhost' IDENTIFIED BY '';
- GRANT ALL PRIVILEGES ON *.* TO 'pbarriat'@'localhost';
- UPDATE user SET plugin='auth_socket' WHERE User='pbarriat';
- UPDATE user SET plugin='unix_socket' WHERE User='pbarriat';
- FLUSH PRIVILEGES;
- exit;
- ```
- ```bash
- sudo service mysql restart
- mysql -u pbarriat
- ```
- ```mysql
- USE mysql;
- create database testdb;
- FLUSH PRIVILEGES;
- exit;
- ```
- ```bash
- pip3 install django
- pip3 install djangorestframework
- ```
- ECLIPSE
- Create Django Project With PyDev Django Wizard
- - django-admin startproject easydata
- - python3 manage.py startapp catalog
- Files:
- M easydata/easydata/settings.py
- M easydata/easydata/urls.py
- A easydata/catalog/urls.py
- ECLIPSE
- python3 manage.py makemigrations
- python3 manage.py migrate
- sudo apt install libldap2-dev libsasl2-dev
- sudo pip3 install django-auth-ldap
- Next, add 'rest_framework' to the INSTALLED_APPS array
- cd ${ECLIPSEWorkspace}/MyApp
- python3 manage.py migrate
- python3 manage.py createsuperuser
- python3 manage.py startapp testapp
- Next, add 'testapp' to the INSTALLED_APPS array
- Now refresh the Django project folder in eclipse
- settings.py
- TEMPLATES = [
- {
- 'DIRS': ['/home/pbarriat/Eclipse/workspace_parallel/MyApp/'],
- urls.py
- from django.contrib import admin
- from django.urls import path,include
- from django.conf.urls import url
- urlpatterns = [
- path('admin/', admin.site.urls),
- url('^testapp/', include(('testapp.urls','testapp'), namespace='testapp')),
- ]
- testapp/urls.py
- from django.contrib import admin
- from django.urls import path
- from django.conf.urls import url
- from . import views
- import testapp
- urlpatterns = [
- path('admin/', admin.site.urls),
- path('testapp', views.testapp, name='testapp'),
- ]
- firstApp/views.py
- def firstApp(request):
- # The html file path relative to TEMPLATE DIRS directory defined in DjangoProjectExample / settings.py file..
- firstApp_file_path = 'firstApp/pages/index.html'
- # The context object will send back to client, it is a dictionary object contains a Message.
- context = {'Message' : 'Welcome to Django world.'}
- return render(request, firstApp_file_path, context)
- Create directory 'pages' in firstApp folder
- Create index.html file in pages directory
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Python Django firstApp</title>
- </head>
- <body>
- {{Message}}
- </body>
- </html>
- ECLIPSE Runs as PyDev:Django
- http://localhost:8000/firstApp/hello
- python3 manage.py makemigrations
- python3 manage.py migrate
|