Python Forum

Full Version: Django startapp problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Can somebody give me a tutorial about creating startapp in django ? I've been following these tutors :

1. https://docs.djangoproject.com/en/1.11/i...utorial01/
2. http://belajar-django.github.io/

and it failed. Tysm in advance Cry Smash
Hi, nengkya. Can you specify which is the problem installing django? Are you on Windows or Linux?
Can make a working start app,for this i use Python 3.6 on Windows(almost same on Linux).
3.6 has virtual environment build in,look at environment Windows and Linux Python 3 environment.

Full run,i use cmder if wonder:
C:\
# Make virtual environment
λ python -m venv django_app
C:\
λ cd django_app

# Activate environment,in Linux is source bin/activate
C:\django_app
λ C:\django_app\Scripts\activate.bat

# Environment is active,then install Django
(django_app) C:\django_app
λ pip install Django
Collecting Django
 Using cached Django-1.11.2-py2.py3-none-any.whl
Collecting pytz (from Django)
 Using cached pytz-2017.2-py2.py3-none-any.whl
Installing collected packages: pytz, Django
Successfully installed Django-1.11.2 pytz-2017.2

# Git install
(django_app) C:\django_app
λ git init
Initialized empty Git repository in C:/django_app/.git/

# Start project
(django_app) C:\django_app
λ django-admin startproject mysite
(django_app) C:\django_app
λ cd mysite

# In folder mysite with manage.py
(django_app) C:\django_app\mysite
λ ls
manage.py*  mysite/

# Start app install
(django_app) C:\django_app\mysite
λ python manage.py startapp polls

# Migrate database setup
(django_app) C:\django_app\mysite
λ python manage.py migrate
Operations to perform:
 Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
 Applying contenttypes.0001_initial... OK
 Applying auth.0001_initial... OK
 Applying admin.0001_initial... OK
 Applying admin.0002_logentry_remove_auto_add... OK
 Applying contenttypes.0002_remove_content_type_name... OK
 Applying auth.0002_alter_permission_name_max_length... OK
 Applying auth.0003_alter_user_email_max_length... OK
 Applying auth.0004_alter_user_username_opts... OK
 Applying auth.0005_alter_user_last_login_null... OK
 Applying auth.0006_require_contenttypes_0002... OK
 Applying auth.0007_alter_validators_add_error_messages... OK
 Applying auth.0008_alter_user_username_max_length... OK
 Applying sessions.0001_initial... OK

# Run Django
(django_app) C:\django_app\mysite
λ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
July 01, 2017 - 10:56:02
Django version 1.11.2, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
in browser http://127.0.0.1:8000/
[Image: 2tvj51.jpg]
In setting.py can add mysite.
# Application definition
INSTALLED_APPS = [
    'mysite', # this is the app we added
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]
Now you good to go,or just use Flask as me Wink
Yes that INSTALLED_APPS = [ doesnt appears on that both tuts. Im in both Win or Linux. I dont use Virtual Environment, n btw already solved guys ty on thi$ https://scotch.io/tutorials/build-your-f...ing-django (y) Now i'm @ https://www.codepolitan.com/tutorial/mem...ango-admin or :

import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import quad

h=6.626e-34
c= 3.0e+8
k= 1.38e-23
shift = 500 # defining the shift

#wav is the wavelength
def planck(wav, T):
   a= 2.0*h*c**2
   b= (h*c)/(wav*k*T)
   intensity = a/( (wav**5) * (np.exp(b)- 1.0) )
   return intensity

wavelengths= np.arange(1e-9, 3e-6, 1e-9)

intensity = planck( wavelengths, 6000.)
# creating a shifted intensity by padding 0 in the begining
# and removing extra values at the end
shifted_intensity = np.concatenate((np.zeros(shift),intensity))[:-shift]

sum_intensity = intensity + shifted_intensity
"""i, err= quad(planck,0,10**4,6000,6000)
print(i)"""

plt.plot(wavelengths*1e9, intensity, 'm-', label= '6000 K')
plt.plot(wavelengths*1e9, shifted_intensity, 'b-', label='6000 K shifted')
plt.plot(wavelengths*1e9, sum_intensity, 'r--',label= 'Summed intensity')

plt.xlabel('Wavelength\n(nm)')
plt.ylabel('Intensity\n(W Sr^-1 m^-3)')
plt.title('Black Body Radiation')
plt.legend()
plt.show()

N can i ask if can use both scikitlearn + django. Already done it with flask --> https://github.com/nengkya/ML_Predict_Name