Giter Club home page Giter Club logo

django-helloworld's Introduction

django-helloworld

A Django 'Hello World' program example.

Installation

You need install the pre-requirements for run this Hello World example.

Update repositories of available packages to install, with the following command:

$ sudo apt update

Install necessary minimum dependencies, with the following command:

$ sudo apt install python3-dev python3-pip python3-virtualenv sqlitebrowser

For run this example need to install Django framework execute the follow command:

$ sudo pip install -r requirements.txt

And later followed by:

$ python3 manage.py migrate

At which point you should see:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions, sites
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 admin.0003_logentry_add_action_flag_choices... 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 auth.0009_alter_user_last_name_max_length... OK
  Applying sessions.0001_initial... OK
  Applying sites.0001_initial... OK
  Applying sites.0002_alter_domain_unique... OK

For use the Django Admin Interface, it's needed to create a superuser for management, with the following command:

$ python3 manage.py createsuperuser --username admin --email [email protected]

At which point you should see:

Password:
Password (again):

Superuser created successfully.

Run application

After which you can run:

$ python3 manage.py runserver

Then, you can open the URL http://127.0.0.1:8000/ in your web browser and you can see the hello world example like this:

A Django 'Hello World' program example

A Django 'Hello World' program example

Also you can open in your web browser the URL http://127.0.0.1:8000/admin for access to the Django Admin Interface like this:

Django Admin Interface running

Django Admin Interface running

django-helloworld's People

Contributors

macagua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

django-helloworld's Issues

question about python3-virtualenv

Hi, I'm using your django hello-world app to experiment creating django apps in kubernetes. I am copying your steps into a Dockerfile and building it.

FROM debian

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y python3-dev python3-pip python3-virtualenv sqlitebrowser && rm -rf /var/lib/apt/lists/*

COPY requirements.txt /

RUN pip install -r requirements.txt
...

and I get an error when it's installing the requirements

...
 => ERROR [ 4/11] RUN pip install -r requirements.txt                                                                                                                                                              0.6s
------                                                                                                                                                                                                                  
 > [ 4/11] RUN pip install -r requirements.txt:                                                                                                                                                                         
#0 0.520 error: externally-managed-environment                                                                                                                                                                          
#0 0.520                                                                                                                                                                                                                
#0 0.520 × This environment is externally managed                                                                                                                                                                       
#0 0.520 ╰─> To install Python packages system-wide, try apt install
#0 0.520     python3-xyz, where xyz is the package you are trying to
#0 0.520     install.
#0 0.520     
#0 0.520     If you wish to install a non-Debian-packaged Python package,
#0 0.520     create a virtual environment using python3 -m venv path/to/venv.
#0 0.520     Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
#0 0.520     sure you have python3-full installed.
#0 0.520     
#0 0.520     If you wish to install a non-Debian packaged Python application,
#0 0.520     it may be easiest to use pipx install xyz, which will manage a
#0 0.520     virtual environment for you. Make sure you have pipx installed.
#0 0.520     
#0 0.520     See /usr/share/doc/python3.11/README.venv for more information.
#0 0.520 
#0 0.520 note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
#0 0.520 hint: See PEP 668 for the detailed specification.
------
Dockerfile:8
--------------------
   6 |     COPY requirements.txt /
   7 |     
   8 | >>> RUN pip install -r requirements.txt
   9 |     
  10 |     RUN mkdir -p /docs
--------------------
ERROR: failed to solve: process "/bin/sh -c pip install -r requirements.txt" did not complete successfully: exit code: 1

So I am thinking it's an error relating to the venv. My question is where is the python3-virtualenv getting used? Should I create a venv to the container before pip install?

No worries if you don't have time. I'll keep investigating and will post a reply if I find an answer.

Error : cannot import name 'patterns' ; How to solve it ?

Traceback (most recent call last): File "manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line utility.execute() File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/__init__.py", line 359, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/base.py", line 294, in run_from_argv self.execute(*args, **cmd_options) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/base.py", line 342, in execute self.check() File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/base.py", line 374, in check include_deployment_checks=include_deployment_checks, File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 62, in _run_checks issues.extend(super(Command, self)._run_checks(**kwargs)) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/base.py", line 361, in _run_checks return checks.run_checks(**kwargs) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks new_errors = check(app_configs=app_configs) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/checks/urls.py", line 14, in check_url_config return check_resolver(resolver) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/checks/urls.py", line 24, in check_resolver for pattern in resolver.url_patterns: File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/urls/resolvers.py", line 313, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/urls/resolvers.py", line 306, in urlconf_module return import_module(self.urlconf_name) File "/Users/robiulislam/anaconda/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 978, in _gcd_import File "<frozen importlib._bootstrap>", line 961, in _find_and_load File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 655, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed File "/Users/robiulislam/personal/personal/urls.py", line 15, in <module> url(r'^polls/$', 'personal.views.polls'), File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/conf/urls/__init__.py", line 85, in url raise TypeError('view must be a callable or a list/tuple in the case of include().') TypeError: view must be a callable or a list/tuple in the case of include(). ROBIULs-MacBook-Pro:personal robiulislam$ cd ./hone -bash: cd: ./hone: No such file or directory ROBIULs-MacBook-Pro:personal robiulislam$ cd /home ROBIULs-MacBook-Pro:home robiulislam$ cd helloworld-master -bash: cd: helloworld-master: No such file or directory ROBIULs-MacBook-Pro:home robiulislam$ ls ROBIULs-MacBook-Pro:home robiulislam$ cd /Users/robiulislam/helloworld-master ROBIULs-MacBook-Pro:helloworld-master robiulislam$ python manage.py migrate \Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line utility.execute() File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/__init__.py", line 359, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/base.py", line 294, in run_from_argv self.execute(*args, **cmd_options) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/base.py", line 342, in execute self.check() File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/base.py", line 374, in check include_deployment_checks=include_deployment_checks, File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 62, in _run_checks issues.extend(super(Command, self)._run_checks(**kwargs)) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/management/base.py", line 361, in _run_checks return checks.run_checks(**kwargs) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks new_errors = check(app_configs=app_configs) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/checks/urls.py", line 14, in check_url_config return check_resolver(resolver) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/core/checks/urls.py", line 24, in check_resolver for pattern in resolver.url_patterns: File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/urls/resolvers.py", line 313, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/Users/robiulislam/anaconda/lib/python3.6/site-packages/django/urls/resolvers.py", line 306, in urlconf_module return import_module(self.urlconf_name) File "/Users/robiulislam/anaconda/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 978, in _gcd_import File "<frozen importlib._bootstrap>", line 961, in _find_and_load File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 655, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed File "/Users/robiulislam/helloworld-master/helloworld/urls.py", line 3, in <module> from django.conf.urls import patterns, include ImportError: cannot import name 'patterns'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.