Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

alex Tarasiuk
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??

Thanks in advance,
Alex.
 





 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

Andréas Kühne
Hi Alex,

You shouldn't have anything regarding the settings in models.py.

Remove:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()

from your models.py file. You should never have any settings in the models.py file at all. Also, you should never reference the django project folder (your first MY_DJANGO here) in the project. It always has that folder anyway.

In settings.py, your INSTALLED_APPS should look like this:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    'my_django',
]


Everything should then work as expected.

Regards,

Andréas

2018-01-05 13:07 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??

Thanks in advance,
Alex.
 





 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCcenCaiZDFrcPPd3WoZgrj_O3d219kOOx27knBCfFs0Wg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

Ramiro Morales-2
In reply to this post by alex Tarasiuk


On Fri, Jan 5, 2018 at 9:07 AM, alex Tarasiuk <[hidden email]> wrote:
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??



You describe the problem you are seeing but don't tell why you are setting things up .

What are you trying to achieve with things like this:

in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

or

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    ...
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

All of this is very unconventional.

If you are starting with Django you should refrain from doing weird things. Django currently does no magic outside the Python import system so there is no need to over complicate.

TBH No upgrade of Django is going to help you the mess you currently have.


--
Ramiro Morales
@ramiromorales

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAO7PdF9xg8_23kATinOgU%2B%2BKTBYPEOhoSBWyjUj3Sdi5d%3DBdHg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

alex Tarasiuk
In reply to this post by Andréas Kühne
Hi Andréas,
Thanks for your response.

When I'm removing the lines you've talked about I'm having the following error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This is why I've added those settings in the first place.



On Friday, January 5, 2018 at 3:59:31 PM UTC+2, Andréas Kühne wrote:
Hi Alex,

You shouldn't have anything regarding the settings in models.py.

Remove:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()

from your models.py file. You should never have any settings in the models.py file at all. Also, you should never reference the django project folder (your first MY_DJANGO here) in the project. It always has that folder anyway.

In settings.py, your INSTALLED_APPS should look like this:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    'my_django',
]


Everything should then work as expected.

Regards,

Andréas

2018-01-05 13:07 GMT+01:00 alex Tarasiuk <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="_D_mBdmIBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">alex...@...>:
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??

Thanks in advance,
Alex.
 





 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="_D_mBdmIBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="_D_mBdmIBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

Andréas Kühne
Ok,

So are you in the folder where the manage.py file resides when you run your commands? You have to be in that directory when running manage.py commands.

Also - as long as you haven't done too much already - I would recommend starting fresh and looking into the tutorials in the django docs pages on how to start a project. See https://docs.djangoproject.com/en/2.0/intro/tutorial01/ or https://tutorial.djangogirls.org/en/.

The settings you have changed there are very strange (as Ramiro pointed out) and should definitely not be required. Have you set the DEFAULT_INDEX_TABLESPACE setting anywhere? Because that is also something that shouldn't be required....

Med vänliga hälsningar,

Andréas

2018-01-05 15:17 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi Andréas,
Thanks for your response.

When I'm removing the lines you've talked about I'm having the following error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This is why I've added those settings in the first place.



On Friday, January 5, 2018 at 3:59:31 PM UTC+2, Andréas Kühne wrote:
Hi Alex,

You shouldn't have anything regarding the settings in models.py.

Remove:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()

from your models.py file. You should never have any settings in the models.py file at all. Also, you should never reference the django project folder (your first MY_DJANGO here) in the project. It always has that folder anyway.

In settings.py, your INSTALLED_APPS should look like this:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    'my_django',
]


Everything should then work as expected.

Regards,

Andréas

2018-01-05 13:07 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??

Thanks in advance,
Alex.
 





 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCcZ-Gii9QS7kVtkKLXUb%2Bc77rZCXFC%2B40cNJjEeUa1bEQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

alex Tarasiuk
Here is what I've done so far (it is a new project and I did followed the tutorial until it didn't worked for me any more).

Here are the steps of how I created the project:

1. django-admin startproject MY_DGANGO

2.  python manage.py startapp my_django

3.  edited the models.py

4. python manage.py makemigrations my_django

5. python manage.py sqlmigrate my_django 0001

6.  python manage.py migrate

 

Now after the tables in the DB was created, I want to use it (add/remove/update date) from my project.


7.  So from my project I’m importing models so I’ll be able to use the classes I’ve created to extract and add information to/from the DB.

For example:

·         In models.py:

Class Person(models.Model):

            first_name = models.CharField(max_length=100, null=False)

            last_name = models.CharField(max_length=100, null=False)

            phone_number = models.CharField(max_length=100, null=False)

            …

 

·         In some file in my project:

from MY_DGANGO.my_django import models

….

def add_person(first_name, last_name, phone_number):

person = models.Person(first_name= first_name, last_name= last_name,

                                    phone_number= phone_number)

person.save()

def get_person_by_phone_number(phone_number):

person = models.Person.objects.filter(phone_number= phone_number)



P.S. I'm runnig it without starting any Django server.



On Friday, January 5, 2018 at 4:29:11 PM UTC+2, Andréas Kühne wrote:
Ok,

So are you in the folder where the manage.py file resides when you run your commands? You have to be in that directory when running manage.py commands.

Also - as long as you haven't done too much already - I would recommend starting fresh and looking into the tutorials in the django docs pages on how to start a project. See <a href="https://docs.djangoproject.com/en/2.0/intro/tutorial01/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Fintro%2Ftutorial01%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEkALyui3yKFLHE3iqGwxBq4G_4eg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Fintro%2Ftutorial01%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEkALyui3yKFLHE3iqGwxBq4G_4eg&#39;;return true;">https://docs.djangoproject.com/en/2.0/intro/tutorial01/ or <a href="https://tutorial.djangogirls.org/en/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Ftutorial.djangogirls.org%2Fen%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFjC3bjRXowr4WnUOZ0oJIDla9VpA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Ftutorial.djangogirls.org%2Fen%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFjC3bjRXowr4WnUOZ0oJIDla9VpA&#39;;return true;">https://tutorial.djangogirls.org/en/.

The settings you have changed there are very strange (as Ramiro pointed out) and should definitely not be required. Have you set the DEFAULT_INDEX_TABLESPACE setting anywhere? Because that is also something that shouldn't be required....

Med vänliga hälsningar,

Andréas

2018-01-05 15:17 GMT+01:00 alex Tarasiuk <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="w3NlbneKBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">alex...@...>:
Hi Andréas,
Thanks for your response.

When I'm removing the lines you've talked about I'm having the following error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This is why I've added those settings in the first place.



On Friday, January 5, 2018 at 3:59:31 PM UTC+2, Andréas Kühne wrote:
Hi Alex,

You shouldn't have anything regarding the settings in models.py.

Remove:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()

from your models.py file. You should never have any settings in the models.py file at all. Also, you should never reference the django project folder (your first MY_DJANGO here) in the project. It always has that folder anyway.

In settings.py, your INSTALLED_APPS should look like this:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    'my_django',
]


Everything should then work as expected.

Regards,

Andréas

2018-01-05 13:07 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??

Thanks in advance,
Alex.
 





 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at <a href="https://groups.google.com/group/django-users" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="w3NlbneKBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="w3NlbneKBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com.

For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e97c0b6-51de-4503-8a89-a0ad4e3269d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

Jani Tiainen

Hi.

You probably want to create Django management command to ease up all settings and such.


Ei viruksia. www.avast.com

On Fri, Jan 5, 2018 at 4:50 PM, alex Tarasiuk <[hidden email]> wrote:
Here is what I've done so far (it is a new project and I did followed the tutorial until it didn't worked for me any more).

Here are the steps of how I created the project:

1. django-admin startproject MY_DGANGO

2.  python manage.py startapp my_django

3.  edited the models.py

4. python manage.py makemigrations my_django

5. python manage.py sqlmigrate my_django 0001

6.  python manage.py migrate

 

Now after the tables in the DB was created, I want to use it (add/remove/update date) from my project.


7.  So from my project I’m importing models so I’ll be able to use the classes I’ve created to extract and add information to/from the DB.

For example:

·         In models.py:

Class Person(models.Model):

            first_name = models.CharField(max_length=100, null=False)

            last_name = models.CharField(max_length=100, null=False)

            phone_number = models.CharField(max_length=100, null=False)

            …

 

·         In some file in my project:

from MY_DGANGO.my_django import models

….

def add_person(first_name, last_name, phone_number):

person = models.Person(first_name= first_name, last_name= last_name,

                                    phone_number= phone_number)

person.save()

def get_person_by_phone_number(phone_number):

person = models.Person.objects.filter(phone_number= phone_number)



P.S. I'm runnig it without starting any Django server.



On Friday, January 5, 2018 at 4:29:11 PM UTC+2, Andréas Kühne wrote:
Ok,

So are you in the folder where the manage.py file resides when you run your commands? You have to be in that directory when running manage.py commands.

Also - as long as you haven't done too much already - I would recommend starting fresh and looking into the tutorials in the django docs pages on how to start a project. See https://docs.djangoproject.com/en/2.0/intro/tutorial01/ or https://tutorial.djangogirls.org/en/.

The settings you have changed there are very strange (as Ramiro pointed out) and should definitely not be required. Have you set the DEFAULT_INDEX_TABLESPACE setting anywhere? Because that is also something that shouldn't be required....

Med vänliga hälsningar,

Andréas

2018-01-05 15:17 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi Andréas,
Thanks for your response.

When I'm removing the lines you've talked about I'm having the following error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This is why I've added those settings in the first place.



On Friday, January 5, 2018 at 3:59:31 PM UTC+2, Andréas Kühne wrote:
Hi Alex,

You shouldn't have anything regarding the settings in models.py.

Remove:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()

from your models.py file. You should never have any settings in the models.py file at all. Also, you should never reference the django project folder (your first MY_DJANGO here) in the project. It always has that folder anyway.

In settings.py, your INSTALLED_APPS should look like this:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    'my_django',
]


Everything should then work as expected.

Regards,

Andréas

2018-01-05 13:07 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??

Thanks in advance,
Alex.
 





 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]om.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]om.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e97c0b6-51de-4503-8a89-a0ad4e3269d6%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHn91od8%2BPWE9imvwG%3D_qSa5dBwm3uDPxVsq2PY6FCCTxSEAJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

Andréas Kühne
In reply to this post by alex Tarasiuk
Ah, 

OK.

Now it is a bit more clear. 

What you are doing is not supported by django. You don't use the django models OUTSIDE of the django project. That is not a supported usecase. You can probably set it up, so that you CAN do that, but I would not recommend it.

What are you trying to accomplish by reading the models OUTSIDE of the django project?

Regards,

Andréas

2018-01-05 15:50 GMT+01:00 alex Tarasiuk <[hidden email]>:
Here is what I've done so far (it is a new project and I did followed the tutorial until it didn't worked for me any more).

Here are the steps of how I created the project:

1. django-admin startproject MY_DGANGO

2.  python manage.py startapp my_django

3.  edited the models.py

4. python manage.py makemigrations my_django

5. python manage.py sqlmigrate my_django 0001

6.  python manage.py migrate

 

Now after the tables in the DB was created, I want to use it (add/remove/update date) from my project.


7.  So from my project I’m importing models so I’ll be able to use the classes I’ve created to extract and add information to/from the DB.

For example:

·         In models.py:

Class Person(models.Model):

            first_name = models.CharField(max_length=100, null=False)

            last_name = models.CharField(max_length=100, null=False)

            phone_number = models.CharField(max_length=100, null=False)

            …

 

·         In some file in my project:

from MY_DGANGO.my_django import models

….

def add_person(first_name, last_name, phone_number):

person = models.Person(first_name= first_name, last_name= last_name,

                                    phone_number= phone_number)

person.save()

def get_person_by_phone_number(phone_number):

person = models.Person.objects.filter(phone_number= phone_number)



P.S. I'm runnig it without starting any Django server.



On Friday, January 5, 2018 at 4:29:11 PM UTC+2, Andréas Kühne wrote:
Ok,

So are you in the folder where the manage.py file resides when you run your commands? You have to be in that directory when running manage.py commands.

Also - as long as you haven't done too much already - I would recommend starting fresh and looking into the tutorials in the django docs pages on how to start a project. See https://docs.djangoproject.com/en/2.0/intro/tutorial01/ or https://tutorial.djangogirls.org/en/.

The settings you have changed there are very strange (as Ramiro pointed out) and should definitely not be required. Have you set the DEFAULT_INDEX_TABLESPACE setting anywhere? Because that is also something that shouldn't be required....

Med vänliga hälsningar,

Andréas

2018-01-05 15:17 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi Andréas,
Thanks for your response.

When I'm removing the lines you've talked about I'm having the following error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This is why I've added those settings in the first place.



On Friday, January 5, 2018 at 3:59:31 PM UTC+2, Andréas Kühne wrote:
Hi Alex,

You shouldn't have anything regarding the settings in models.py.

Remove:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()

from your models.py file. You should never have any settings in the models.py file at all. Also, you should never reference the django project folder (your first MY_DJANGO here) in the project. It always has that folder anyway.

In settings.py, your INSTALLED_APPS should look like this:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    'my_django',
]


Everything should then work as expected.

Regards,

Andréas

2018-01-05 13:07 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??

Thanks in advance,
Alex.
 





 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]om.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e97c0b6-51de-4503-8a89-a0ad4e3269d6%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCeR1sqF1dKNnARvu7chOAJOmDRLX4wmUWas3DHB8sDkWw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

alex Tarasiuk
The only thing I need from Django (at this point) is to have the ability to communicate with my DB.
(person = models.Person.objects.filter(phone_number= phone_number) from my previous example)
I'm planning to use the admin page and I might add a GUI in some point.

Regards,
Alex

On Friday, January 5, 2018 at 5:10:20 PM UTC+2, Andréas Kühne wrote:
Ah, 

OK.

Now it is a bit more clear. 

What you are doing is not supported by django. You don't use the django models OUTSIDE of the django project. That is not a supported usecase. You can probably set it up, so that you CAN do that, but I would not recommend it.

What are you trying to accomplish by reading the models OUTSIDE of the django project?

Regards,

Andréas

2018-01-05 15:50 GMT+01:00 alex Tarasiuk <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="5A5dLLaMBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">alex...@...>:
Here is what I've done so far (it is a new project and I did followed the tutorial until it didn't worked for me any more).

Here are the steps of how I created the project:

1. django-admin startproject MY_DGANGO

2.  python manage.py startapp my_django

3.  edited the models.py

4. python manage.py makemigrations my_django

5. python manage.py sqlmigrate my_django 0001

6.  python manage.py migrate

 

Now after the tables in the DB was created, I want to use it (add/remove/update date) from my project.


7.  So from my project I’m importing models so I’ll be able to use the classes I’ve created to extract and add information to/from the DB.

For example:

·         In models.py:

Class Person(models.Model):

            first_name = models.CharField(max_length=100, null=False)

            last_name = models.CharField(max_length=100, null=False)

            phone_number = models.CharField(max_length=100, null=False)

            …

 

·         In some file in my project:

from MY_DGANGO.my_django import models

….

def add_person(first_name, last_name, phone_number):

person = models.Person(first_name= first_name, last_name= last_name,

                                    phone_number= phone_number)

person.save()

def get_person_by_phone_number(phone_number):

person = models.Person.objects.filter(phone_number= phone_number)



P.S. I'm runnig it without starting any Django server.



On Friday, January 5, 2018 at 4:29:11 PM UTC+2, Andréas Kühne wrote:
Ok,

So are you in the folder where the manage.py file resides when you run your commands? You have to be in that directory when running manage.py commands.

Also - as long as you haven't done too much already - I would recommend starting fresh and looking into the tutorials in the django docs pages on how to start a project. See <a href="https://docs.djangoproject.com/en/2.0/intro/tutorial01/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Fintro%2Ftutorial01%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEkALyui3yKFLHE3iqGwxBq4G_4eg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Fintro%2Ftutorial01%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEkALyui3yKFLHE3iqGwxBq4G_4eg&#39;;return true;">https://docs.djangoproject.com/en/2.0/intro/tutorial01/ or <a href="https://tutorial.djangogirls.org/en/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Ftutorial.djangogirls.org%2Fen%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFjC3bjRXowr4WnUOZ0oJIDla9VpA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Ftutorial.djangogirls.org%2Fen%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFjC3bjRXowr4WnUOZ0oJIDla9VpA&#39;;return true;">https://tutorial.djangogirls.org/en/.

The settings you have changed there are very strange (as Ramiro pointed out) and should definitely not be required. Have you set the DEFAULT_INDEX_TABLESPACE setting anywhere? Because that is also something that shouldn't be required....

Med vänliga hälsningar,

Andréas

2018-01-05 15:17 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi Andréas,
Thanks for your response.

When I'm removing the lines you've talked about I'm having the following error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This is why I've added those settings in the first place.



On Friday, January 5, 2018 at 3:59:31 PM UTC+2, Andréas Kühne wrote:
Hi Alex,

You shouldn't have anything regarding the settings in models.py.

Remove:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()

from your models.py file. You should never have any settings in the models.py file at all. Also, you should never reference the django project folder (your first MY_DJANGO here) in the project. It always has that folder anyway.

In settings.py, your INSTALLED_APPS should look like this:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    'my_django',
]


Everything should then work as expected.

Regards,

Andréas

2018-01-05 13:07 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??

Thanks in advance,
Alex.
 





 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at <a href="https://groups.google.com/group/django-users" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at <a href="https://groups.google.com/group/django-users" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com.

For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="5A5dLLaMBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="5A5dLLaMBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/5e97c0b6-51de-4503-8a89-a0ad4e3269d6%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/5e97c0b6-51de-4503-8a89-a0ad4e3269d6%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/5e97c0b6-51de-4503-8a89-a0ad4e3269d6%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/5e97c0b6-51de-4503-8a89-a0ad4e3269d6%40googlegroups.com.

For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c09c5b64-8244-4f4d-9d43-acc091919fce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

Jani Tiainen
In reply to this post by Andréas Kühne
Hi.

That is a bit misleading information.

It is completely supported using models (and other Django stuff) from standalone scripts wihtout using manage.py


And specially part:

And you don't even need settings.py file - that is purely optional as well.


On Fri, Jan 5, 2018 at 5:09 PM, Andréas Kühne <[hidden email]> wrote:
Ah, 

OK.

Now it is a bit more clear. 

What you are doing is not supported by django. You don't use the django models OUTSIDE of the django project. That is not a supported usecase. You can probably set it up, so that you CAN do that, but I would not recommend it.

What are you trying to accomplish by reading the models OUTSIDE of the django project?

Regards,

Andréas

2018-01-05 15:50 GMT+01:00 alex Tarasiuk <[hidden email]>:
Here is what I've done so far (it is a new project and I did followed the tutorial until it didn't worked for me any more).

Here are the steps of how I created the project:

1. django-admin startproject MY_DGANGO

2.  python manage.py startapp my_django

3.  edited the models.py

4. python manage.py makemigrations my_django

5. python manage.py sqlmigrate my_django 0001

6.  python manage.py migrate

 

Now after the tables in the DB was created, I want to use it (add/remove/update date) from my project.


7.  So from my project I’m importing models so I’ll be able to use the classes I’ve created to extract and add information to/from the DB.

For example:

·         In models.py:

Class Person(models.Model):

            first_name = models.CharField(max_length=100, null=False)

            last_name = models.CharField(max_length=100, null=False)

            phone_number = models.CharField(max_length=100, null=False)

            …

 

·         In some file in my project:

from MY_DGANGO.my_django import models

….

def add_person(first_name, last_name, phone_number):

person = models.Person(first_name= first_name, last_name= last_name,

                                    phone_number= phone_number)

person.save()

def get_person_by_phone_number(phone_number):

person = models.Person.objects.filter(phone_number= phone_number)



P.S. I'm runnig it without starting any Django server.



On Friday, January 5, 2018 at 4:29:11 PM UTC+2, Andréas Kühne wrote:
Ok,

So are you in the folder where the manage.py file resides when you run your commands? You have to be in that directory when running manage.py commands.

Also - as long as you haven't done too much already - I would recommend starting fresh and looking into the tutorials in the django docs pages on how to start a project. See https://docs.djangoproject.com/en/2.0/intro/tutorial01/ or https://tutorial.djangogirls.org/en/.

The settings you have changed there are very strange (as Ramiro pointed out) and should definitely not be required. Have you set the DEFAULT_INDEX_TABLESPACE setting anywhere? Because that is also something that shouldn't be required....

Med vänliga hälsningar,

Andréas

2018-01-05 15:17 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi Andréas,
Thanks for your response.

When I'm removing the lines you've talked about I'm having the following error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This is why I've added those settings in the first place.



On Friday, January 5, 2018 at 3:59:31 PM UTC+2, Andréas Kühne wrote:
Hi Alex,

You shouldn't have anything regarding the settings in models.py.

Remove:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()

from your models.py file. You should never have any settings in the models.py file at all. Also, you should never reference the django project folder (your first MY_DJANGO here) in the project. It always has that folder anyway.

In settings.py, your INSTALLED_APPS should look like this:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    'my_django',
]


Everything should then work as expected.

Regards,

Andréas

2018-01-05 13:07 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??

Thanks in advance,
Alex.
 





 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]om.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]om.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e97c0b6-51de-4503-8a89-a0ad4e3269d6%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCeR1sqF1dKNnARvu7chOAJOmDRLX4wmUWas3DHB8sDkWw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHn91ofk%3DbcyVuPB9rUpO_Tkv%3Dbbbfsos8bHgvrxwdA4RJ7eJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

Jani Tiainen
In reply to this post by alex Tarasiuk
Hi,

As I did few posts already, you can do it few ways.

I would recommend using custom management command. It will wrap up things nicely under Django hood, you don't need to figure out how to apply settings and such which allows you just need to concentrate to make your code to work.

You can create standalone script as well, it just requires a bit more work since you would be responsible of making sure that you have setup Django properly.


On Fri, Jan 5, 2018 at 5:17 PM, alex Tarasiuk <[hidden email]> wrote:
The only thing I need from Django (at this point) is to have the ability to communicate with my DB.
(person = models.Person.objects.filter(phone_number= phone_number) from my previous example)
I'm planning to use the admin page and I might add a GUI in some point.

Regards,
Alex

On Friday, January 5, 2018 at 5:10:20 PM UTC+2, Andréas Kühne wrote:
Ah, 

OK.

Now it is a bit more clear. 

What you are doing is not supported by django. You don't use the django models OUTSIDE of the django project. That is not a supported usecase. You can probably set it up, so that you CAN do that, but I would not recommend it.

What are you trying to accomplish by reading the models OUTSIDE of the django project?

Regards,

Andréas

2018-01-05 15:50 GMT+01:00 alex Tarasiuk <[hidden email]>:
Here is what I've done so far (it is a new project and I did followed the tutorial until it didn't worked for me any more).

Here are the steps of how I created the project:

1. django-admin startproject MY_DGANGO

2.  python manage.py startapp my_django

3.  edited the models.py

4. python manage.py makemigrations my_django

5. python manage.py sqlmigrate my_django 0001

6.  python manage.py migrate

 

Now after the tables in the DB was created, I want to use it (add/remove/update date) from my project.


7.  So from my project I’m importing models so I’ll be able to use the classes I’ve created to extract and add information to/from the DB.

For example:

·         In models.py:

Class Person(models.Model):

            first_name = models.CharField(max_length=100, null=False)

            last_name = models.CharField(max_length=100, null=False)

            phone_number = models.CharField(max_length=100, null=False)

            …

 

·         In some file in my project:

from MY_DGANGO.my_django import models

….

def add_person(first_name, last_name, phone_number):

person = models.Person(first_name= first_name, last_name= last_name,

                                    phone_number= phone_number)

person.save()

def get_person_by_phone_number(phone_number):

person = models.Person.objects.filter(phone_number= phone_number)



P.S. I'm runnig it without starting any Django server.



On Friday, January 5, 2018 at 4:29:11 PM UTC+2, Andréas Kühne wrote:
Ok,

So are you in the folder where the manage.py file resides when you run your commands? You have to be in that directory when running manage.py commands.

Also - as long as you haven't done too much already - I would recommend starting fresh and looking into the tutorials in the django docs pages on how to start a project. See https://docs.djangoproject.com/en/2.0/intro/tutorial01/ or https://tutorial.djangogirls.org/en/.

The settings you have changed there are very strange (as Ramiro pointed out) and should definitely not be required. Have you set the DEFAULT_INDEX_TABLESPACE setting anywhere? Because that is also something that shouldn't be required....

Med vänliga hälsningar,

Andréas

2018-01-05 15:17 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi Andréas,
Thanks for your response.

When I'm removing the lines you've talked about I'm having the following error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This is why I've added those settings in the first place.



On Friday, January 5, 2018 at 3:59:31 PM UTC+2, Andréas Kühne wrote:
Hi Alex,

You shouldn't have anything regarding the settings in models.py.

Remove:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()

from your models.py file. You should never have any settings in the models.py file at all. Also, you should never reference the django project folder (your first MY_DJANGO here) in the project. It always has that folder anyway.

In settings.py, your INSTALLED_APPS should look like this:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    'my_django',
]


Everything should then work as expected.

Regards,

Andréas

2018-01-05 13:07 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??

Thanks in advance,
Alex.
 





 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]om.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]om.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e97c0b6-51de-4503-8a89-a0ad4e3269d6%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c09c5b64-8244-4f4d-9d43-acc091919fce%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHn91odC8Ga%3D4T06QNe6ZkWPe02p8npxAaE%2BddD9ZhfGrWwgXw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Failing to configure Django correctlly (conflict in settings between models.py and manage.py usage).

Andréas Kühne
In reply to this post by Jani Tiainen
Yeah, OK, didn't know about that ability - have never used it :-)

Regards,

Andréas

2018-01-05 16:21 GMT+01:00 Jani Tiainen <[hidden email]>:
Hi.

That is a bit misleading information.

It is completely supported using models (and other Django stuff) from standalone scripts wihtout using manage.py


And specially part:

And you don't even need settings.py file - that is purely optional as well.


On Fri, Jan 5, 2018 at 5:09 PM, Andréas Kühne <[hidden email]> wrote:
Ah, 

OK.

Now it is a bit more clear. 

What you are doing is not supported by django. You don't use the django models OUTSIDE of the django project. That is not a supported usecase. You can probably set it up, so that you CAN do that, but I would not recommend it.

What are you trying to accomplish by reading the models OUTSIDE of the django project?

Regards,

Andréas

2018-01-05 15:50 GMT+01:00 alex Tarasiuk <[hidden email]>:
Here is what I've done so far (it is a new project and I did followed the tutorial until it didn't worked for me any more).

Here are the steps of how I created the project:

1. django-admin startproject MY_DGANGO

2.  python manage.py startapp my_django

3.  edited the models.py

4. python manage.py makemigrations my_django

5. python manage.py sqlmigrate my_django 0001

6.  python manage.py migrate

 

Now after the tables in the DB was created, I want to use it (add/remove/update date) from my project.


7.  So from my project I’m importing models so I’ll be able to use the classes I’ve created to extract and add information to/from the DB.

For example:

·         In models.py:

Class Person(models.Model):

            first_name = models.CharField(max_length=100, null=False)

            last_name = models.CharField(max_length=100, null=False)

            phone_number = models.CharField(max_length=100, null=False)

            …

 

·         In some file in my project:

from MY_DGANGO.my_django import models

….

def add_person(first_name, last_name, phone_number):

person = models.Person(first_name= first_name, last_name= last_name,

                                    phone_number= phone_number)

person.save()

def get_person_by_phone_number(phone_number):

person = models.Person.objects.filter(phone_number= phone_number)



P.S. I'm runnig it without starting any Django server.



On Friday, January 5, 2018 at 4:29:11 PM UTC+2, Andréas Kühne wrote:
Ok,

So are you in the folder where the manage.py file resides when you run your commands? You have to be in that directory when running manage.py commands.

Also - as long as you haven't done too much already - I would recommend starting fresh and looking into the tutorials in the django docs pages on how to start a project. See https://docs.djangoproject.com/en/2.0/intro/tutorial01/ or https://tutorial.djangogirls.org/en/.

The settings you have changed there are very strange (as Ramiro pointed out) and should definitely not be required. Have you set the DEFAULT_INDEX_TABLESPACE setting anywhere? Because that is also something that shouldn't be required....

Med vänliga hälsningar,

Andréas

2018-01-05 15:17 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi Andréas,
Thanks for your response.

When I'm removing the lines you've talked about I'm having the following error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This is why I've added those settings in the first place.



On Friday, January 5, 2018 at 3:59:31 PM UTC+2, Andréas Kühne wrote:
Hi Alex,

You shouldn't have anything regarding the settings in models.py.

Remove:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()

from your models.py file. You should never have any settings in the models.py file at all. Also, you should never reference the django project folder (your first MY_DJANGO here) in the project. It always has that folder anyway.

In settings.py, your INSTALLED_APPS should look like this:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    'my_django',
]


Everything should then work as expected.

Regards,

Andréas

2018-01-05 13:07 GMT+01:00 alex Tarasiuk <[hidden email]>:
Hi, I'm new to Django and having some trouble to configure it.
I'm using Django 1.11.9 (1.11.5 at first but then upgraded with hopes it will solve the issue) and Python 2.7.12 from virtualenv.

Here is my project structure (Please pay attention to upper/lower case letters - it is intentionally):

<my project>:

module 1

module 2

...

...

MY_DJANGO:

MY_DJANGO:

            __init__.py

            settings.py

            urls.py

wsgi.py

my_django:

            migrations

            __init__.py

            admin.py

            apps.py

            models.py

            tests.py

            views.py

__init__.py

manage.py

 
in models.py I've added:
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = "MY_DJANGO.MY_DJANGO.settings"
django.setup()
before the models import from django.db.

in manage.py, in the main
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO.settings")
was auto generated by Django 

in settings.py, in INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.admindocs',
    ======>>>>'MY_DJANGO.my_django', or 'my_django', <<<<===== Here is the problem
]

Problem description:
if I use 'MY_DJANGO.my_django' in INSTALLED_APPS then running 'python manage.py check' command yields:
 ImportError: No module named MY_DJANGO.settings


 
and if I use 'my_django' in INSTALLED_APPS then I have an import error while importing models:
 from MY_DJANGO.my_django import models (in some file) yields:
ImportError: No module named my_django 

Also tried to add  ''my_django.apps.MyDjangoConfig' to INSTALLED_APPS, and it didn't helped.

What am I doing wrong??

Thanks in advance,
Alex.
 





 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]om.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb9251bb-7bce-4eec-b8ac-90b031db1284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]om.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/31d7a9d0-a861-4814-a4d5-9771ba828918%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e97c0b6-51de-4503-8a89-a0ad4e3269d6%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCeR1sqF1dKNnARvu7chOAJOmDRLX4wmUWas3DHB8sDkWw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHn91ofk%3DbcyVuPB9rUpO_Tkv%3Dbbbfsos8bHgvrxwdA4RJ7eJg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCe7EXvjk0eku1%3D7JGo2EFCTWbUSDbT6GbmSgOb%2BjzdrdA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.