Re: Django Newb Help

2016-03-18 Thread parker smith
I resolved this problem.

On Wednesday, 16 March 2016 18:07:08 UTC-7, parker smith wrote:
>
> I can modify position and look of the {{ form.to }} with  style="position: absolute;">{{ form.to }} tags and css but I don't 
> think that's the intention...
>
> On Wednesday, 16 March 2016 16:45:31 UTC-7, parker smith wrote:
>>
>> Hello,
>>
>> I am working on the django by example book and in ch. 2 I am having 
>> issues getting the recipient email to display inside the template tag...
>>
>> here is the specific line of code that isn't working and what I changed 
>> it to to get it some what working...
>>
>> views.py code referencing cd - 
>>
>>   
>>   cd = form.cleaned_data
>>   
>>  send_mail(subject, message,'ad...@myblog.com',[cd['to']])
>>
>>
>> code having issues - location is share.html
>>   
>>   ...
>>   "{{ post.title }}" was successfully sent to {{ cd.to }}.
>>   ...
>>
>>
>> everything is displaying fine except that the {{ cd.to }} section is 
>> just blank like this
>>
>>   
>>Post 3 was successfully sent to .
>>
>>
>> however if I replace it with {{ form.to }} I do see the recipient email 
>> address but it is floated to the left and is surrounded in in a grey box 
>> with padding... so that it displays like 
>>
>>   bl...@email.com Post 3 was successfully sent to .
>>
>>
>>
>>
>> I hope I am being clear and am hoping to get a better answer on how to 
>> get it to display properly.
>>
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/36db9fbe-7a18-4d62-b3cb-9539d07c8da7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to save multiple image to its associated foreign key object?

2016-03-18 Thread Tushant Khatiwada
I have posted a question in SO but hasnt got any reply yet. Heres the link 
for my question. Could anyone please help me? 
http://stackoverflow.com/questions/36001532/multiple-image-not-saved-to-its-foreign-key-object

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/29d4be59-d6c0-44d0-8dd2-699defa18378%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django ImportError: No module named admin

2016-03-18 Thread addison . slabaugh
As a result of attempting to update admin.py of one of my Django apps, I 
now get a Server Error (500) that has brought my site down. When I import 
admin from django.contrib, I get the following traceback:

Traceback (most recent call last):
 File 
"/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", 
line 74, in autodiscover_modules
   import_module('%s.%s' % (app_config.name, module_to_search))
 File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
   __import__(name)
ImportError: No module named admin

Using print_stack() gives me a little deeper insight:

File "/home/ubuntu/gather/src/foodshop/wsgi.py", line 21, in 
  application = get_wsgi_application()
File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, 
in get_wsgi_application
  django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, 
in setup
  apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 
115, in populate
  app_config.ready()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/apps.py", 
line 22, in ready
  self.module.autodiscover()
File 
"/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", 
line 24, in autodiscover
  autodiscover_modules('admin', register_to=site)
File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py"
, line 74, in autodiscover_modules
  import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
  __import__(name)
File "/home/ubuntu/gather/src/recipes/admin.py", line 6, in 
  class RecipesAdmin(admin.ModelAdmin):
File "/home/ubuntu/gather/src/recipes/admin.py", line 9, in RecipesAdmin
  traceback.print_stack()

I use this module in several other apps within my project, so I don't 
understand why it's not working for this particular app. You can see my 
very simple Python code below, which is for an admin.

*admin.py*
from django.contrib import admin
from .models import Recipes

class RecipesAdmin(admin.ModelAdmin):
list_display = ["__unicode__", "title", "rating", "date_modified"]
prepopulated_fields = {"slug": ("SKU",)}
class Meta:
model = Recipes

admin.site.register(Recipes, RecipesAdmin)

*urls.py*
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.conf.urls import patterns, url, include
from djangoratings.views import AddRatingFromModel

urlpatterns = [

url(r'^$', 'customers.views.home', name='home'),
url(r'^home/', 'customers.views.home', name='home'),
url(r'^about/', 'recipes.views.about', name='about'),
url(r'^menu/', 'recipes.views.menu', name='menu'),
url(r'^donate/', 'recipes.views.menu', name='menu'),
# url(r'^contact/', 'recipes.views.contact', name='contact'),

url(r'^admin/', include(admin.site.urls)),

url(r'^about/healthy/', 'recipes.views.healthy', name='healthy'),
url(r'^about/premade/', 'recipes.views.premade', name='premade'),
url(r'^about/exceptional/', 'recipes.views.exceptional', name=
'exceptional'),

url(r'^accounts/', include('registration.backends.default.urls')),

url(r'^cart/', 'cart.views.get_cart', name='get_cart'),
url(r'^add/', 'recipes.views.menu', name='menu'),
# url(r'^add/(?P[-\w]+)/id=(?P[-\w]+)/$', 
'cart.views.add_to_cart', name='shopping-cart-add'),
url(r'^update/(?P[-\w]+)/$', 'cart.views.specific_qty', name
='shopping-cart-specify'),
url(r'^remove/(?P[-\w]+)/$', 'cart.views.remove_from_cart', 
name='shopping-cart-remove'),
url(r'^subtract/(?P[-\w]+)/$', 
'cart.views.subtract_from_cart', name='shopping-cart-subtract'),
url(r'^clear_cart/', 'cart.views.clear_cart', name='shopping-cart-clear'
),

url(r'^contact/$','contact.views.email',name='email'),
url(r'^feedback/$','contact.views.feedback',name='feedback'),
url(r'^thanks/$', 'contact.views.thanks',name='thanks'),
url(r'^profile/$', 'cart.views.profile', name='profile'),
url(r'^profile/new/$', 'cart.views.new_profile', name='new_profile'),
url(r'^profile/error/$', 'cart.views.qty_error', name='qty_error'),
url(r'^profile/cancel/$', 'cart.views.cancel_sub', name='cancel_sub'),
url(r'^profile/feedback/$', 'recipes.views.feedback', name='feedback'),

url(r'^rate/(?P\d+)/(?P\d+)/', AddRatingFromModel(), {
'app_label': 'recipes',
'model': 'recipes',
'field_name': 'rating',
}),

url(r'^charge/$', 'cart.views.charge', name='charge'),
url(r'^subscription/charge/$', 'cart.views.pay', name='pay'),

url(r'^frequently_asked/$', 'cart.views.frequently_asked', name=
'frequently_asked'),
url(r'^tender/$', 'cart.views.weekly_orders', name='weekly_orders'),
url(r'^tender_postmates/$', 'cart.views.tender_postmates', name=
'tender_postmates')

] + stat

server connection reset when click on localhost: Python error: wsgiref-> simple_server.py "noneType" object has no attribute split

2016-03-18 Thread amarshall

So I'm moving my work environment from one environment to the next. I did a 
pip install -r requirements for a list of packages I had. setup the DB. 
Migration went good. I do runserver and that runs. BUT when I click on the 
link to the homepage it says "The Connection was reset" in my browser. In 
my stacktrace is the below message. I've searched and found similar errors 
on the internet but none django related with a fix. any help

Here's the traceback I get:

Exception happened during processing of request from ('127.0.0.1', 56784)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 593, in 
process_request_thread
self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
  File 
"/home/adrian/.virtualenvs/sneak8env/local/lib/python2.7/site-packages/django/core/servers/basehttp.py"
, line 102, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/lib/python2.7/SocketServer.py", line 649, in __init__
self.handle()
  File 
"/home/adrian/.virtualenvs/sneak8env/local/lib/python2.7/site-packages/django/core/servers/basehttp.py"
, line 182, in handle
handler.run(self.server.get_app())
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 92, in run
self.close()
  File "/usr/lib/python2.7/wsgiref/simple_server.py", line 33, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'



-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/cc20b9d6-7ed1-43a1-90fd-f4f9cd52fdde%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Forms vs Angularjs

2016-03-18 Thread Gorkem Tolan
I am a new comer to Django. Last four weeks I have been working on web 
application purely created with Django framework. 
I realized that Django forms are very cumbersome to use. 
I'd rather have DRF (rest framework) and just angularjs form. I am sure 
alot users will bombard me tons of oppositions. 
I'd like to hear the oppositions and critics maybe I am missing some points 
and knowledge. 
Thanks,

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/cbad3f35-721e-4dbd-ae6d-f08395d4a0cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Forms in Django

2016-03-18 Thread 술욱
2016-03-18 15:17 GMT-03:00 Stanislav Vasko :

> Ufff, i hope there is another way. Something working so simple like
> passing data from View to Template with direct access like {{ company.name
> }} or {{ company.phone }}. I dont see the point why to modify Model and how
> it helps with styling form.
>

You won't be modifying the model.  Just the form.

You need to tell Django to render the form using the css clases you want.

There are a few ways of doing that. One is Fred's way:

phone = forms.CharField(
required   = True,
max_length = 50,
label  = u'',
widget = forms.TextInput(
attrs={
'class'   : 'form-control',
   }
)

You can also do a custom template. So instead of letting Django render the
form, you code the html yourself.

This is, instead of:

{{ form.as_p }}

do something like:

{% csrf_token %}




...



My favorite is to install django-crispy-forms, but may be overkill at the
moment since you are just learning Django. If you are comfortable using
modules/third-party apps, your template will be:

{% load crispy_forms_tags %}
{% crispy form %}


HTH,
Norberto

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CADut3oAL_1bG1KOZb2DRhAN%2BcWqtbfDKYTTUSCqH-XVsSOECWw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Newbie - Tutorial Recommendations?

2016-03-18 Thread Stanislav Vasko
Hello,

i found very usefull general tutorial at Django 
site: https://docs.djangoproject.com/en/1.9/intro/tutorial01/

But you can try DjangoGirls (dont worry, its not just for 
girls): http://tutorial.djangogirls.org

Good Luck!

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/e62fffa8-a35d-4e66-a392-15e35566ab87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: custom FORMAT_SETTINGS

2016-03-18 Thread Erik Stein


Nevermind, I reused the locale-directory for the format-definitions and 
didn't realize, that the path has to be a python module (or: didn't 
realize, that the locale directory isn't a module by default).


best
-- erik



On 18.03.2016 11:08, Erik Stein wrote:


hello --

I'd like to extend Django's localized formats by my own defaults, using
the FORMAT_MODULE_PATH setting, e.g. to have those:

SHORT_DAY_ONLY_FORMAT = 'd.'
SHORT_DAYMONTH_FORMAT = 'd.N.'
DATE_RANGE_SEPARATOR = '–'

Sadly, in django.utils.formats.get_format Django checks the hard coded
list of possible FORMAT_SETTINGS and returns the placeholder string if
it doesn't know the format.

Do I missing something or is it just not possible currently to extend
the default formats?

best
-- erik



--
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/56EC4847.3020403%40classlibrary.net.
For more options, visit https://groups.google.com/d/optout.


Re: Forms in Django

2016-03-18 Thread Fred Stluka

Stanislav (aka Stanley?),

As my company motto says:  "Glad to be of service!".

I'm very impressed with Django.  It's a mature product that does
a good job of:
"Making simple things easy, and complex things possible"
It has good simple default behaviors, but also hooks that you
can use to drill down to more detail when necessary.


For example, in my Django templates, I sometimes use:

{{form}}

but sometimes have to resort to:

{{ form.first_name }}
{{ form.last_name }}
{{ form.phone }}

and occasionally even:

{{ form.first_name.value }}
{{ form.first_name.label }}
{{ form.first_name.errors }}

{{ form.last_name.value }}
{{ form.last_name.label }}
{{ form.last_name.errors }}

{{ form.phone.value }}
{{ form.phone.label }}
{{ form.phone.errors }}


Similarly, in my Django ModelForms, I sometimes use:

class PersonModelForm(forms.ModelForm):
class Meta:
model=Person

but sometimes have to resort to:

class PersonModelForm(forms.ModelForm):
class Meta:
model=Person
fields = ['first_name', 'last_name', 'phone',]

and occasionally even:

class PersonModelForm(forms.ModelForm):
class Meta:
model=Person
exclude = ['middle_name',]

or take over a field explicitly as:

phone = forms.CharField(
required   = True,
max_length = 50,
label  = u'',
widget = forms.TextInput(
attrs={
'class'   : 'form-control',
'id'  : 'my_custom_HTML_id',
'placeholder' : 'Phone',
}
),
)

or even give up on doing it all declaratively and do something
more dynamic in the __init__() of the Form, as:

def set_placeholders_from_labels(form):
for field in form.fields.itervalues():
field.widget.attrs['placeholder'] = field.label

class PersonForm(forms.Form):
def __init__(self, *args, **kwargs):
super(Donate2Form, self).__init__(*args, **kwargs)

set_placeholders_from_labels(self)
self.fields['amount'].widget.attrs['placeholder'] = ""

if some_special_reason():
self.fields['amount'].initial = "100"

keep_enabled = ['first_name','last_name']
if some_mode_where_we_need_some_fields_disabled():
for field in self.fields:
if field not in keep_enabled:
self.fields[field].widget.attrs['disabled'] = True


And with validation of user-entered data, I can declare many
validation rules on the declarations of the fields, and can do
validation programmatically in the clean_field_name() methods
and the overall clean() method.  Or can even use the clean()
method of the Model instead of the clean() method of the form.


The ORM has similar hooks.  I can use it simply, to get() and
save() models from and to the DB.  Or can do fancier queries.
Or can drop down into raw SQL if necessary.


And I can use middleware to inject all sorts of useful functionality
into the HTTP request/response cycle, to change or add to the
default behavior, add caching of DB data, Django templates,
and fully assembled Django pages, etc.


And I can hook into Django "signals" for more sophisticated
needs.


Very powerful!

And I've found the community to be extraordinarily friendly and
helpful also.

Enjoy!
--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 3/18/16 3:54 PM, Stanislav Vasko wrote:
This is exactly what i was looking for, many thanks! Now i can render 
form i need and like. Now i will test and i hope it will be same easy 
to write data back to db.


Many thanks, Stanley

Dne pátek 18. března 2016 20:50:37 UTC+1 Fred Stluka napsal(a):

Stanislav,

Try these:

{{ form.title.value }}
{{ form.title.label }}
{{ form.title.errors }}
etc.

--Fred

Fred Stluka -- mailt...@bristle.com  --
http://bristle.com/~fred/ 
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 3/18/16 2:55 PM, Stanislav Vasko wrote:

This is exactly what im trying. But if i enter *{{ form.title }}*
i get not the data to use in form, but whole:

**

But as i study doc, there is no simple way like Django is
providing in other part. So, maybe Fred's way is a good one (but
quite strange) and still dont know how i will make Fieldsets and
other stuff (i need to work with data and some the result).

Maybe there is some better Django Form plugin, but i prefer not
to use anything outside Django, because noone knows how it will

Re: Deploying Django via wsgi

2016-03-18 Thread parallaxplace
Thank you all for your replies. It turned out to be something simple. Since 
Django was installed in a virtualenv I needed to include the path to the 
Django libs in the wsgi paths. Done and site up.

Again thanks!



On Tuesday, March 15, 2016 at 5:00:10 AM UTC-7, parall...@gmail.com wrote:
>
> Quite new, and trying to deploy first Django site. I keep getting 503 
> errors. Here are the particulars, any hints as to what I'm doing wrong 
> would be much appreciated! All directories and files are group owned and 
> writable by www-data. Ubuntu server, and Apache2.4 server where I have root 
> access. The tutorial where I got the howto is located here:
>
> https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04
>
> Thank you!
>
> *File structure/location:*
>
> /home/user/kb_venv/project_name/
> __init__.py
> settings.py
> urls.py
> wsgi.py
> manage.py
> app_name
>
> /home/user/kb_venv/project_name/project_name/
> apache/
> __init__.py
> override.py
> wsgi.py
>
>
> *override.py file contents:*
> from project_name.settings import
> DEBUG = True
> #ALLOWED_HOSTS = ['104.131.154.99'] (no domain name, I'm using IP to 
> access the site)
>
> *wsgi.py file contents:*
> #wsgi.py
> import os, sys
> # Calculate the path based on the location of the WSGI script.
> apache_configuration= os.path.dirname(__file__)
> project = os.path.dirname(apache_configuration)
> workspace = os.path.dirname(project)
> sys.path.append(workspace)
> sys.path.append(project)
>
> # Add the path to 3rd party django application and to django itself.
> sys.path.append('/home/smlake/kb_venv')
> os.environ['DJANGO_SETTINGS_MODULE'] = 'project_name.apache.override'
> from django.core.wsgi import get_wsgi_application
> application = get_wsgi_application()
>
> *Apache2.4 000-default file:*
> 
>
> WSGIScriptAlias / /home/smlake/kb_venv/project_name/apache/wsgi.py
> 
>   Require all granted
> 
> ServerAdmin parallaxpl...@gmail.com
> DocumentRoot /home/smlake/kb_venv/project_name/project_name
>
> ErrorLog ${APACHE_LOG_DIR}/error.log
> CustomLog ${APACHE_LOG_DIR}/access.log combined
>
> 
>
>
> *Apache error log entry:*
> [Mon Mar 14 23:58:48.413099 2016] [authz_core:error] [pid 8034:tid 
> 140480713053952] [client 54.188.195.80:57782] AH01630: client denied by 
> server configuration: /home/user/kb_venv/project_name/
>
>
>
>
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/e62e0685-ce4e-44a2-8693-6e3cefeba776%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.